const path = require('path');
const load = require('../helpers/load.js');

function runSpecs(title, dir, showCompletionTable, options) {
  options = options || {};
  const specs = load.loadFiles(path.resolve(__dirname, dir));

  if (showCompletionTable) {
    load.outputCompletionTable(title, specs);
  }

  describe(title, () => {
    Object.keys(specs).forEach(section => {
      describe(section, () => {
        specs[section].specs.forEach((spec) => {
          spec.options = Object.assign({}, options, (spec.options || {}));
          const example = (spec.example ? ' example ' + spec.example : '');
          const passFail = (spec.shouldFail ? 'fail' : 'pass');
          if (typeof spec.options.silent === 'undefined') {
            spec.options.silent = true;
          }
          if (spec.options.sanitizer) {
            // eslint-disable-next-line no-eval
            spec.options.sanitizer = eval(spec.options.sanitizer);
          }
          (spec.only ? fit : (spec.skip ? xit : it))('should ' + passFail + example, async() => {
            const before = process.hrtime();
            if (spec.shouldFail) {
              await expectAsync(spec).not.toRender(spec.html);
            } else {
              await expectAsync(spec).toRender(spec.html);
            }
            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`);
            }
          });
        });
      });
    });
  });
}

runSpecs('GFM', './gfm', true, { gfm: true, pedantic: false, headerIds: false });
runSpecs('CommonMark', './commonmark', true, { gfm: false, pedantic: false, headerIds: false });
runSpecs('Original', './original', false, { gfm: false, pedantic: true });
runSpecs('New', './new');
runSpecs('ReDOS', './redos');
runSpecs('Security', './security', false, { silent: true }); // silent - do not show deprecation warning

@@ -662,24 +662,25 @@
  : 'pass');%0A
+%0A
           if
@@ -771,32 +771,33 @@
 ue;%0A          %7D%0A
+%0A
           if (sp
@@ -939,32 +939,43 @@
 r);%0A          %7D%0A
+          %0A
           (spec.
@@ -1132,24 +1132,24 @@
 ouldFail) %7B%0A
-
             
@@ -1191,32 +1191,143 @@
 der(spec.html);%0A
+            %7D else if (spec.options.deepEqual) %7B%0A              await expectAsync(spec).toDeepEqual(spec.html);%0A
             %7D el

add condition for deepEqual rules