-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
57 lines (48 loc) · 1.71 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
import assert from 'node:assert/strict'
import test from 'node:test'
import rehypeParse from 'rehype-parse'
import rehypePicture from 'rehype-picture'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'
test('rehypePicture', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('rehype-picture')).sort(), [
'default'
])
})
await t.test('should ignore non-matching images', async function () {
const file = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypePicture)
.use(rehypeStringify)
.process('<img src="cat.png">')
assert.equal(String(file), '<img src="cat.png">')
})
await t.test('should ignore images without src', async function () {
const file = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypePicture, {})
.use(rehypeStringify)
.process('<img>')
assert.equal(String(file), '<img>')
})
await t.test('should work without replacement map', async function () {
const file = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypePicture, {jpg: undefined})
.use(rehypeStringify)
.process('<img src="cat.jpg">')
assert.equal(String(file), '<picture><img src="cat.jpg"></picture>')
})
await t.test('should add sources', async function () {
const file = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypePicture, {jpg: {webp: 'image/webp'}})
.use(rehypeStringify)
.process('<img src="cat.jpg">')
assert.equal(
String(file),
'<picture><source srcset="cat.webp" type="image/webp"><img src="cat.jpg"></picture>'
)
})
})