2019-04-25 09:42:38 -05:00
|
|
|
const path = require('path');
|
|
|
|
const load = require('../helpers/load.js');
|
2019-04-25 07:52:11 -05:00
|
|
|
|
2019-04-25 13:40:32 -05:00
|
|
|
function runSpecs (title, dir, showCompletionTable, options) {
|
2019-04-25 07:52:11 -05:00
|
|
|
options = options || {};
|
2019-04-25 09:42:38 -05:00
|
|
|
const specs = load.loadFiles(path.resolve(__dirname, dir));
|
2019-03-09 23:37:33 -06:00
|
|
|
|
2019-04-25 09:42:38 -05:00
|
|
|
if (showCompletionTable) {
|
|
|
|
load.outputCompletionTable(title, specs);
|
|
|
|
}
|
2019-04-25 07:52:11 -05:00
|
|
|
|
2019-03-11 11:12:46 -05:00
|
|
|
describe(title, () => {
|
2019-03-09 23:37:33 -06:00
|
|
|
Object.keys(specs).forEach(section => {
|
2019-03-11 11:12:46 -05:00
|
|
|
describe(section, () => {
|
2019-04-09 13:19:50 -05:00
|
|
|
specs[section].specs.forEach((spec) => {
|
2019-04-25 07:52:11 -05:00
|
|
|
spec.options = Object.assign({}, options, (spec.options || {}));
|
2019-03-11 11:12:46 -05:00
|
|
|
(spec.only ? fit : it)('should ' + (spec.shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, () => {
|
2019-04-25 09:42:38 -05:00
|
|
|
const before = process.hrtime();
|
2019-03-09 23:37:33 -06:00
|
|
|
if (spec.shouldFail) {
|
|
|
|
expect(spec).not.toRender(spec.html);
|
|
|
|
} else {
|
|
|
|
expect(spec).toRender(spec.html);
|
|
|
|
}
|
2019-04-25 09:42:38 -05:00
|
|
|
const elapsed = process.hrtime(before);
|
|
|
|
if (elapsed[0] > 0) {
|
|
|
|
const s = (elapsed[0] + elapsed[1] * 1e-9).toFixed(3);
|
|
|
|
fail(`took too long: ${s}s`);
|
|
|
|
}
|
2019-03-09 23:37:33 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-04-25 09:42:38 -05:00
|
|
|
}
|
2019-04-25 07:52:11 -05:00
|
|
|
|
2019-04-25 13:40:32 -05:00
|
|
|
runSpecs('GFM', './gfm', true, { gfm: true });
|
|
|
|
runSpecs('CommonMark', './commonmark', true, { headerIds: false });
|
|
|
|
runSpecs('Original', './original', false, { gfm: false });
|
2019-04-25 09:42:38 -05:00
|
|
|
runSpecs('New', './new');
|
|
|
|
runSpecs('Redos', './redos');
|