/
index.js
55 lines (42 loc) · 1.15 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
44
45
46
47
48
49
50
51
52
53
54
55
'use strict'
var fs = require('fs')
var path = require('path')
var test = require('tape')
var remark = require('remark')
var negate = require('negate')
var hidden = require('is-hidden')
var toc = require('..')
var read = fs.readFileSync
var join = path.join
var root = join(__dirname, 'fixtures')
var fixtures = fs.readdirSync(root)
function process(value, config) {
return remark()
.use(toc, config)
.processSync(value)
.toString()
}
test('remark-toc()', function(t) {
t.equal(typeof toc, 'function', 'should be a function')
t.doesNotThrow(function() {
toc.call(remark())
}, 'should not throw if not passed options')
t.end()
})
test('Fixtures', function(t) {
fixtures.filter(negate(hidden)).forEach(function(fixture) {
var filepath = join(root, fixture)
var output = read(join(filepath, 'output.md'), 'utf-8')
var input = read(join(filepath, 'input.md'), 'utf-8')
var config
var result
try {
config = JSON.parse(read(join(filepath, 'config.json')))
} catch (_) {
config = {}
}
result = process(input, config)
t.equal(result, output, 'should work on `' + fixture + '`')
})
t.end()
})