2
0

run-spec.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { dirname, resolve } from 'path';
  2. import { fileURLToPath } from 'url';
  3. import { loadFiles, outputCompletionTable } from '../helpers/load.js';
  4. const __dirname = dirname(fileURLToPath(import.meta.url));
  5. function runSpecs(title, dir, showCompletionTable, options) {
  6. options = options || {};
  7. const specs = loadFiles(resolve(__dirname, dir));
  8. if (showCompletionTable) {
  9. outputCompletionTable(title, specs);
  10. }
  11. describe(title, () => {
  12. Object.keys(specs).forEach(section => {
  13. describe(section, () => {
  14. specs[section].specs.forEach((spec) => {
  15. spec.options = Object.assign({}, options, (spec.options || {}));
  16. const example = (spec.example ? ' example ' + spec.example : '');
  17. const passFail = (spec.shouldFail ? 'fail' : 'pass');
  18. if (typeof spec.options.silent === 'undefined') {
  19. spec.options.silent = true;
  20. }
  21. (spec.only ? fit : (spec.skip ? xit : it))('should ' + passFail + example, async() => {
  22. const before = process.hrtime();
  23. if (spec.shouldFail) {
  24. await expectAsync(spec).not.toRender(spec.html);
  25. } else if (spec.options.renderExact) {
  26. await expectAsync(spec).toRenderExact(spec.html);
  27. } else {
  28. await expectAsync(spec).toRender(spec.html);
  29. }
  30. const elapsed = process.hrtime(before);
  31. if (elapsed[0] > 0) {
  32. const s = (elapsed[0] + elapsed[1] * 1e-9).toFixed(3);
  33. fail(`took too long: ${s}s`);
  34. }
  35. });
  36. });
  37. });
  38. });
  39. });
  40. }
  41. runSpecs('GFM', './gfm', true, { gfm: true, pedantic: false });
  42. runSpecs('CommonMark', './commonmark', true, { gfm: false, pedantic: false });
  43. runSpecs('Original', './original', false, { gfm: false, pedantic: true });
  44. runSpecs('New', './new');
  45. runSpecs('ReDOS', './redos');