marked/test/specs/run-spec.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { loadFiles, outputCompletionTable } from '../helpers/load.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
2019-04-25 07:52:11 -05:00
function runSpecs(title, dir, showCompletionTable, options) {
2019-04-25 07:52:11 -05:00
options = options || {};
const specs = loadFiles(resolve(__dirname, dir));
2019-03-09 23:37:33 -06:00
2019-04-25 09:42:38 -05:00
if (showCompletionTable) {
outputCompletionTable(title, specs);
2019-04-25 09:42:38 -05:00
}
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-07-02 10:03:46 -05:00
if (typeof spec.options.silent === 'undefined') {
spec.options.silent = true;
}
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);
} else if (spec.options.renderExact) {
await expectAsync(spec).toRenderExact(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
runSpecs('GFM', './gfm', true, { gfm: true, pedantic: false });
runSpecs('CommonMark', './commonmark', true, { gfm: false, pedantic: false });
2019-07-01 08:12:01 -05:00
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');