-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
remark-toc.js | ||
remark-toc.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,55 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var test = require('tape'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var remark = require('remark'); | ||
var negate = require('negate'); | ||
var hidden = require('is-hidden'); | ||
var toc = require('..'); | ||
var test = require('tape') | ||
var fs = require('fs') | ||
var path = require('path') | ||
var remark = require('remark') | ||
var negate = require('negate') | ||
var hidden = require('is-hidden') | ||
var toc = require('..') | ||
|
||
var read = fs.readFileSync; | ||
var exists = fs.existsSync; | ||
var join = path.join; | ||
var read = fs.readFileSync | ||
var join = path.join | ||
|
||
var ROOT = join(__dirname, 'fixtures'); | ||
var ROOT = join(__dirname, 'fixtures') | ||
|
||
var fixtures = fs.readdirSync(ROOT); | ||
var fixtures = fs.readdirSync(ROOT) | ||
|
||
function process(value, config) { | ||
return remark().use(toc, config).processSync(value).toString(); | ||
return remark() | ||
.use(toc, config) | ||
.processSync(value) | ||
.toString() | ||
} | ||
|
||
test('remark-toc()', function (t) { | ||
t.equal(typeof toc, 'function', 'should be a function'); | ||
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.doesNotThrow(function() { | ||
toc.call(remark()) | ||
}, 'should not throw if not passed options') | ||
|
||
t.end(); | ||
}); | ||
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 = join(filepath, 'config.json'); | ||
var result; | ||
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 | ||
|
||
config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {}; | ||
result = process(input, config); | ||
try { | ||
config = JSON.parse(read(join(filepath, 'config.json'))) | ||
} catch (err) { | ||
config = {} | ||
} | ||
|
||
t.equal(result, output, 'should work on `' + fixture + '`'); | ||
}); | ||
result = process(input, config) | ||
|
||
t.end(); | ||
}); | ||
t.equal(result, output, 'should work on `' + fixture + '`') | ||
}) | ||
|
||
t.end() | ||
}) |