-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.js
105 lines (97 loc) · 3.34 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
99
100
101
102
103
104
105
import assert from 'node:assert/strict'
import test from 'node:test'
import rehypeStringify from 'rehype-stringify'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import remarkStringify from 'remark-stringify'
import {unified} from 'unified'
test('remarkRehype', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('remark-rehype')).sort(), [
'default',
'defaultFootnoteBackContent',
'defaultFootnoteBackLabel',
'defaultHandlers'
])
})
await t.test('should mutate', async function () {
assert.equal(
String(
await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeStringify)
.process('## Hello, world! ##')
),
'<h2>Hello, world!</h2>'
)
})
await t.test('should mutate with options', async function () {
assert.equal(
String(
await unified()
.use(remarkParse)
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeStringify, {allowDangerousHtml: true})
.process('## Hello, <i>world</i>! ##')
),
'<h2>Hello, <i>world</i>!</h2>'
)
})
await t.test(
'should mutate with `processor: undefined` and options',
async function () {
assert.equal(
String(
await unified()
.use(remarkParse)
// @ts-expect-error: this is not typed as being supported w/ the overload, but always was.
.use(remarkRehype, undefined, {allowDangerousHtml: true})
.use(rehypeStringify, {allowDangerousHtml: true})
.process('## Hello, <i>world</i>! ##')
),
'<h2>Hello, <i>world</i>!</h2>'
)
}
)
await t.test('should bridge', async function () {
assert.equal(
String(
await unified()
.use(remarkParse)
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
.use(remarkRehype, unified())
.use(remarkStringify)
.process('## Hello, world! ##')
),
'## Hello, world!\n'
)
})
await t.test('should bridge with options', async function () {
assert.equal(
String(
await unified()
.use(remarkParse)
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
.use(remarkRehype, unified(), {allowDangerousHtml: true})
.use(remarkStringify)
.process('## Hello, <i>world</i>! ##')
),
'## Hello, <i>world</i>!\n'
)
})
await t.test('should understand bridge types', async function () {
const treeIn = unified().use(remarkParse).parse('hi')
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
const treeOut = await unified().use(remarkRehype, unified()).run(treeIn)
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
const doc = unified().use(remarkStringify).stringify(treeOut)
assert.equal(doc, 'hi\n')
})
await t.test('should understand mutate types', async function () {
const treeIn = unified().use(remarkParse).parse('hi')
const treeOut = await unified().use(remarkRehype).run(treeIn)
const doc = unified().use(rehypeStringify).stringify(treeOut)
assert.equal(doc, '<p>hi</p>')
})
})