marked/test/specs/run-spec.js

33 lines
990 B
JavaScript
Raw Normal View History

2019-03-09 23:37:33 -06:00
function runSpecs(title, file, options) {
const json = require(file);
const specs = json.reduce((obj, spec) => {
if (!obj[spec.section]) {
obj[spec.section] = [];
}
obj[spec.section].push(spec);
return obj;
}, {});
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, () => {
specs[section].forEach((spec) => {
2019-03-09 23:37:33 -06:00
if (options) {
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-03-09 23:37:33 -06:00
if (spec.shouldFail) {
expect(spec).not.toRender(spec.html);
} else {
expect(spec).toRender(spec.html);
}
});
});
});
});
});
};
runSpecs('GFM 0.28', './gfm/gfm.0.28.json', {gfm: true});
runSpecs('CommonMark 0.28', './commonmark/commonmark.0.28.json', {headerIds: false});