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-26 21:00:40 -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-04-25 14:48:53 -05:00
|
|
|
const example = (spec.example ? ' example ' + spec.example : '');
|
|
|
|
const passFail = (spec.shouldFail ? 'fail' : 'pass');
|
2020-04-16 10:40:52 +03:00
|
|
|
|
2019-07-02 10:03:46 -05:00
|
|
|
if (typeof spec.options.silent === 'undefined') {
|
|
|
|
spec.options.silent = true;
|
|
|
|
}
|
2020-04-16 10:40:52 +03:00
|
|
|
|
2019-06-28 21:31:03 +02:00
|
|
|
if (spec.options.sanitizer) {
|
|
|
|
// eslint-disable-next-line no-eval
|
|
|
|
spec.options.sanitizer = eval(spec.options.sanitizer);
|
2019-06-27 01:30:01 +02:00
|
|
|
}
|
2020-04-16 10:40:52 +03:00
|
|
|
|
2019-08-27 13:56:04 -05:00
|
|
|
(spec.only ? fit : (spec.skip ? xit : it))('should ' + passFail + example, async() => {
|
2019-04-25 09:42:38 -05:00
|
|
|
const before = process.hrtime();
|
2019-03-09 23:37:33 -06:00
|
|
|
if (spec.shouldFail) {
|
2019-08-27 13:56:04 -05:00
|
|
|
await expectAsync(spec).not.toRender(spec.html);
|
2020-04-16 10:40:52 +03:00
|
|
|
} else if (spec.options.deepEqual) {
|
|
|
|
await expectAsync(spec).toDeepEqual(spec.html);
|
2019-03-09 23:37:33 -06:00
|
|
|
} else {
|
2019-08-27 13:56:04 -05:00
|
|
|
await expectAsync(spec).toRender(spec.html);
|
2019-03-09 23:37:33 -06:00
|
|
|
}
|
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-07-02 00:23:57 -05:00
|
|
|
runSpecs('GFM', './gfm', true, { gfm: true, pedantic: false, headerIds: false });
|
2019-07-01 08:12:01 -05:00
|
|
|
runSpecs('CommonMark', './commonmark', true, { gfm: false, pedantic: false, headerIds: false });
|
|
|
|
runSpecs('Original', './original', false, { gfm: false, pedantic: true });
|
2019-04-25 09:42:38 -05:00
|
|
|
runSpecs('New', './new');
|
2019-05-03 21:01:22 -05:00
|
|
|
runSpecs('ReDOS', './redos');
|
2019-06-27 01:30:01 +02:00
|
|
|
runSpecs('Security', './security', false, { silent: true }); // silent - do not show deprecation warning
|