marked/test/specs/run-spec.js

47 lines
1.6 KiB
JavaScript
Raw Normal View History

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
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');
2019-06-27 01:30:01 +02:00
if (spec.options.sanitizerRemoveHtml) {
spec.options.sanitizer = () => '';
2019-06-27 01:30:01 +02:00
}
2019-04-25 14:48:53 -05:00
(spec.only ? fit : it)('should ' + passFail + 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');
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