-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
98 lines (91 loc) · 2.48 KB
/
test.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import assert from 'node:assert/strict'
import test from 'node:test'
import rehypeStringify from 'rehype-stringify'
import {remark} from 'remark'
import remarkFrontmatter from 'remark-frontmatter'
import remarkRehype from 'remark-rehype'
import remarkYamlConfig from 'remark-yaml-config'
import {unified} from 'unified'
test('remark-yaml-config', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('remark-yaml-config')).sort(), [
'default'
])
})
await t.test('should not throw without compiler', async function () {
assert.doesNotThrow(function () {
unified().use(remarkYamlConfig).freeze()
})
})
await t.test('should not fail without yaml', async function () {
assert.equal(
String(
await remark()
.use(remarkFrontmatter)
.use(remarkYamlConfig)
.process('# Foo bar\n')
),
'# Foo bar\n'
)
})
await t.test('should not fail on empty yaml', async function () {
assert.equal(
String(
await remark()
.use(remarkFrontmatter)
.use(remarkYamlConfig)
.process('---\n---')
),
'---\n---\n'
)
})
await t.test('should set stringification options', async function () {
assert.equal(
String(
await remark()
.use(remarkFrontmatter)
.use(remarkYamlConfig)
.process('---\nremark:\n bullet: "*"\n---\n- Foo')
),
'---\nremark:\n bullet: "*"\n---\n\n* Foo\n'
)
})
await t.test('should throw exceptions', async function () {
try {
await remark()
.use(remarkFrontmatter)
.use(remarkYamlConfig)
.process('---\nremark:\n bullet: "?"\n---\n- Foo')
assert.fail()
} catch (error) {
assert.match(
String(error),
/Cannot serialize items with `\?` for `options.bullet`/
)
}
})
await t.test('should work with a different compiler', async function () {
assert.equal(
String(
await remark()
.use(remarkFrontmatter)
.use(remarkYamlConfig)
.use(remarkRehype)
.use(rehypeStringify)
.process(
[
'---',
'remark:',
' commonmark: true',
' bullet: "*"',
'---',
'',
'1. Foo',
''
].join('\n')
)
),
'<ol>\n<li>Foo</li>\n</ol>'
)
})
})