mocha-parallel / mocha-parallel-tests

Parallel test runner for mocha tests. Looking for maintainer.
MIT License
200 stars 45 forks source link

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

Open adriaandotcom opened 4 years ago

adriaandotcom commented 4 years ago

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)
1999 commented 4 years ago

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

adriaandotcom commented 4 years ago

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.