-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.test.js
56 lines (51 loc) · 1.43 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
51
52
53
54
55
56
import {unified} from 'unified'
import parse from 'remark-parse'
import remark2rehype from 'remark-rehype'
import stringify from 'rehype-stringify'
import * as vfile from 'to-vfile'
import rehypeImgSize from './index'
beforeAll(() => {
process.chdir('fixtures')
})
afterAll(() => {
process.chdir('..')
})
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.toString()).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.toString()).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.toString()).toBe(`<h1>Hello, world!</h1>
<p><img src="https://example.com/img.png" alt=""></p>`)
done()
})
})