forked from ksoichiro/rehype-img-size
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
50 lines (46 loc) · 1.38 KB
/
index.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
const unified = require('unified')
const parse = require('remark-parse')
const remark2rehype = require('remark-rehype')
const stringify = require('rehype-stringify')
const vfile = require('to-vfile')
const rehypeImgSize = require('./index')
process.chdir('fixtures')
test('images in the same directory', (done) => {
unified()
.use(parse)
.use(remark2rehype)
.use(rehypeImgSize)
.use(stringify)
.process(vfile.readSync('test.md'), function(err, file) {
expect(err).toBeNull()
expect(file.contents).toBe(`<h1>Hello, world!</h1>
<p><img src="img.png" alt="" width="640" height="480"></p>`)
done()
})
})
test('images in sub directory', (done) => {
unified()
.use(parse)
.use(remark2rehype)
.use(rehypeImgSize, { dir: 'static' })
.use(stringify)
.process(vfile.readSync('sub.md'), function(err, file) {
expect(err).toBeNull()
expect(file.contents).toBe(`<h1>Hello, world!</h1>
<p><img src="/img/sub.png" alt="" width="320" height="240"></p>`)
done()
})
})
test('external images are ignored', (done) => {
unified()
.use(parse)
.use(remark2rehype)
.use(rehypeImgSize)
.use(stringify)
.process(vfile.readSync('ext.md'), function(err, file) {
expect(err).toBeNull()
expect(file.contents).toBe(`<h1>Hello, world!</h1>
<p><img src="https://example.com/img.png" alt=""></p>`)
done()
})
})