-
-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathstringify.js
More file actions
45 lines (36 loc) · 1.26 KB
/
stringify.js
File metadata and controls
45 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @import {Node} from 'unist'
*/
import assert from 'node:assert/strict'
import test from 'node:test'
import {unified} from 'unified'
import {VFile} from 'vfile'
test('`stringify`', async function (t) {
const givenFile = new VFile('alpha')
const givenNode = {type: 'bravo'}
await t.test('should throw without `compiler`', async function () {
assert.throws(function () {
unified().stringify(givenNode)
}, /Cannot `stringify` without `compiler`/)
})
await t.test('should support a plain function', async function () {
const processor = unified()
processor.compiler = function (node, file) {
assert.equal(node, givenNode)
assert.ok(file instanceof VFile)
assert.equal(arguments.length, 2)
return 'echo'
}
assert.equal(processor.stringify(givenNode, givenFile), 'echo')
})
await t.test('should support an arrow function', async function () {
const processor = unified()
// Note: arrow function intended (which doesn’t have a prototype).
processor.compiler = (node, file) => {
assert.equal(node, givenNode, 'should pass a node')
assert.ok(file instanceof VFile, 'should pass a file')
return 'echo'
}
assert.equal(processor.stringify(givenNode, givenFile), 'echo')
})
})