|
1 | | -'use strict'; |
| 1 | +'use strict' |
2 | 2 |
|
3 | | -var test = require('tape'); |
4 | | -var fs = require('fs'); |
5 | | -var path = require('path'); |
6 | | -var remark = require('remark'); |
7 | | -var negate = require('negate'); |
8 | | -var hidden = require('is-hidden'); |
9 | | -var toc = require('..'); |
| 3 | +var test = require('tape') |
| 4 | +var fs = require('fs') |
| 5 | +var path = require('path') |
| 6 | +var remark = require('remark') |
| 7 | +var negate = require('negate') |
| 8 | +var hidden = require('is-hidden') |
| 9 | +var toc = require('..') |
10 | 10 |
|
11 | | -var read = fs.readFileSync; |
12 | | -var exists = fs.existsSync; |
13 | | -var join = path.join; |
| 11 | +var read = fs.readFileSync |
| 12 | +var join = path.join |
14 | 13 |
|
15 | | -var ROOT = join(__dirname, 'fixtures'); |
| 14 | +var ROOT = join(__dirname, 'fixtures') |
16 | 15 |
|
17 | | -var fixtures = fs.readdirSync(ROOT); |
| 16 | +var fixtures = fs.readdirSync(ROOT) |
18 | 17 |
|
19 | 18 | function process(value, config) { |
20 | | - return remark().use(toc, config).processSync(value).toString(); |
| 19 | + return remark() |
| 20 | + .use(toc, config) |
| 21 | + .processSync(value) |
| 22 | + .toString() |
21 | 23 | } |
22 | 24 |
|
23 | | -test('remark-toc()', function (t) { |
24 | | - t.equal(typeof toc, 'function', 'should be a function'); |
| 25 | +test('remark-toc()', function(t) { |
| 26 | + t.equal(typeof toc, 'function', 'should be a function') |
25 | 27 |
|
26 | | - t.doesNotThrow(function () { |
27 | | - toc.call(remark()); |
28 | | - }, 'should not throw if not passed options'); |
| 28 | + t.doesNotThrow(function() { |
| 29 | + toc.call(remark()) |
| 30 | + }, 'should not throw if not passed options') |
29 | 31 |
|
30 | | - t.end(); |
31 | | -}); |
| 32 | + t.end() |
| 33 | +}) |
32 | 34 |
|
33 | | -test('Fixtures', function (t) { |
34 | | - fixtures.filter(negate(hidden)).forEach(function (fixture) { |
35 | | - var filepath = join(ROOT, fixture); |
36 | | - var output = read(join(filepath, 'output.md'), 'utf-8'); |
37 | | - var input = read(join(filepath, 'input.md'), 'utf-8'); |
38 | | - var config = join(filepath, 'config.json'); |
39 | | - var result; |
| 35 | +test('Fixtures', function(t) { |
| 36 | + fixtures.filter(negate(hidden)).forEach(function(fixture) { |
| 37 | + var filepath = join(ROOT, fixture) |
| 38 | + var output = read(join(filepath, 'output.md'), 'utf-8') |
| 39 | + var input = read(join(filepath, 'input.md'), 'utf-8') |
| 40 | + var config |
| 41 | + var result |
40 | 42 |
|
41 | | - config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {}; |
42 | | - result = process(input, config); |
| 43 | + try { |
| 44 | + config = JSON.parse(read(join(filepath, 'config.json'))) |
| 45 | + } catch (err) { |
| 46 | + config = {} |
| 47 | + } |
43 | 48 |
|
44 | | - t.equal(result, output, 'should work on `' + fixture + '`'); |
45 | | - }); |
| 49 | + result = process(input, config) |
46 | 50 |
|
47 | | - t.end(); |
48 | | -}); |
| 51 | + t.equal(result, output, 'should work on `' + fixture + '`') |
| 52 | + }) |
| 53 | + |
| 54 | + t.end() |
| 55 | +}) |
0 commit comments