-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
68 lines (62 loc) · 1.63 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
import test from 'tape'
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import {ParseEnglish} from 'parse-english'
import retextEnglish from 'retext-english'
import rehypeStringify from 'rehype-stringify'
import retextStringify from 'retext-stringify'
import rehypeRetext from './index.js'
const doc = [
'<!doctype html>',
'<html>',
' <head>',
' <meta charset=utf8>',
' <title>Alpha</title>',
' </head>',
' <body>',
' <p>Bravo</p>',
' </head>',
'</html>'
].join('\n')
test('rehypeRetext', async (t) => {
t.throws(
() => {
// @ts-expect-error: runtime.
unified().use(rehypeRetext).freeze()
},
/Expected `parser` \(such as from `parse-english`\) or `processor` \(a unified pipeline\) as `options`/,
'should throw when w/o parser or processor'
)
t.equal(
unified()
.use(rehypeParse, {fragment: true})
.use(rehypeRetext, ParseEnglish)
// @ts-expect-error: to do: remove this when `retext-stringify` is released.
.use(retextStringify)
.processSync(doc)
.toString(),
'Bravo',
'should mutate'
)
const file = await unified()
.use(rehypeParse)
// @ts-expect-error: to do: remove this when `retext-stringify` is released, hopefully.
.use(rehypeRetext, unified().use(retextEnglish))
.use(rehypeStringify)
.process(doc)
t.equal(
file.toString(),
[
'<!doctype html><html><head>',
' <meta charset="utf8">',
' <title>Alpha</title>',
' </head>',
' <body>',
' <p>Bravo</p>',
' ',
'</body></html>'
].join('\n'),
'should bridge'
)
t.end()
})