mocha-parallel-tests icon indicating copy to clipboard operation
mocha-parallel-tests copied to clipboard

Feature request: support mocha private Mocha.Suite.create API

Open adriaandotcom opened this issue 5 years ago • 2 comments

When using this code:

// const Mocha = require("mocha");
const Mocha = require("mocha-parallel-tests").default;
const { expect } = require("chai");

const mochaInstance = new Mocha();
mochaInstance.timeout(90000);

const suiteInstance = Mocha.Suite.create(mochaInstance.suite, "Test Suite");

suiteInstance.addTest(
  new Mocha.Test(`Testing 1 is not 2`, async function() {
    expect(1).to.be.equal(2);
  })
);

mochaInstance.run(amountFailures => {
  process.exitCode = amountFailures > 0;
});

The output is (empty lines):



When using require("mocha") instead it returns fine:

  Test Suite
    1) Testing 1 is not 2


  0 passing (12ms)
  1 failing

  1) Test Suite
       Testing 1 is not 2:

      AssertionError: expected 1 to equal 2
      + expected - actual

      -1
      +2
      
      at Context.<anonymous> (bug.js:12:21)
      at processImmediate (internal/timers.js:439:21)

adriaandotcom avatar Feb 18 '20 21:02 adriaandotcom

I'm not sure Mocha.Suite.create is a public mocha API.

1999 avatar Feb 25 '20 20:02 1999

It's the only way to have dynamically generate async tests: https://github.com/simpleanalytics/scripts/pull/5/files#diff-910eb6f57886ca16c136101fb1699231R118. It's uncommon, but I think it's the only way to run tests when you don't use the cli.

adriaandotcom avatar Feb 26 '20 14:02 adriaandotcom