-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
39 lines (33 loc) · 1.2 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
import assert from 'node:assert/strict'
import test from 'node:test'
import {rehype} from 'rehype'
import rehypeInferTitleMeta from 'rehype-infer-title-meta'
import rehypeMeta from 'rehype-meta'
test('rehypeInferTitleMeta', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(
Object.keys(await import('rehype-infer-title-meta')).sort(),
['default']
)
})
await t.test('should set a title (in `data.meta`)', async function () {
const file = await rehype().use(rehypeInferTitleMeta).process('<h1>a</h1>')
assert.deepEqual(file.data, {meta: {title: 'a'}})
})
await t.test('should support `options.selector`', async function () {
const file = await rehype()
.use(rehypeInferTitleMeta, {selector: '.x'})
.process('<h1>a</h1><p class=x>b</p>')
assert.deepEqual(file.data, {meta: {title: 'b'}})
})
await t.test('should integrate w/ `rehype-meta`', async function () {
const file = await rehype()
.use(rehypeInferTitleMeta)
.use(rehypeMeta)
.process('<h1>a</h1>')
assert.equal(
String(file),
'<html><head>\n<title>a</title>\n</head><body><h1>a</h1></body></html>'
)
})
})