-
Notifications
You must be signed in to change notification settings - Fork 52
/
index.js
43 lines (36 loc) · 1.01 KB
/
index.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
import {readdirSync as directory, readFileSync as file} from 'fs'
import {join} from 'path'
import ava from 'ava'
import unified from 'unified'
import reParse from 'remark-parse'
import stringify from 'rehype-stringify'
import remark2rehype from 'remark-rehype'
const base = join(__dirname, 'fixtures')
const specs = directory(base).reduce((tests, contents) => {
const parts = contents.split('.')
if (!tests[parts[0]]) {
tests[parts[0]] = {}
}
tests[parts[0]][parts[1]] = file(join(base, contents), 'utf-8')
return tests
}, {})
const entrypoints = [
'../dist',
'../src',
]
entrypoints.forEach(entrypoint => {
const plugin = require(entrypoint)
Object.keys(specs).filter(Boolean).forEach(name => {
if (name === 'regression-1') return
const spec = specs[name]
ava(name, t => {
const {contents} = unified()
.use(reParse)
.use(remark2rehype)
.use(plugin)
.use(stringify)
.processSync(spec.fixture)
t.deepEqual(contents, spec.expected)
})
})
})