Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions test/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ program
.option('-g, --grep <grep>', 'Only run tests matching this string or regexp', '.*')
.option('-j, --jobs <jobs>', 'Number of concurrent jobs for --parallel; use 1 to run in serial, default: (number of CPU cores / 2)', Math.ceil(require('os').cpus().length / 2))
.option('--reporter <reporter>', 'Specify reporter to use', '')
.option('--trial-run', 'Only collect the matching tests and report them as passing')
.option('--timeout <timeout>', 'Specify test timeout threshold (in milliseconds), default: 10000', 10000)
.action(async (command) => {
// Collect files
const files = collectFiles(path.join(process.cwd(), command.args[0]), command.args.slice(1));
const rootSuite = new Mocha.Suite('', new Mocha.Context(), true);

console.log(`Parsing ${files.length} test files`);
if (!command.reporter) {
// TODO: extend reporter interface.
console.log(`Parsing ${files.length} test files`);
}
let total = 0;
// Build the test model, suite per file.
for (const file of files) {
Expand All @@ -54,28 +58,35 @@ program
let runner;
await new Promise(f => {
runner = mocha.run(f);
runner.on(constants.EVENT_RUN_BEGIN, () => {
process.stdout.write(colors.yellow('\u00B7'));
});
if (!command.reporter) {
runner.on(constants.EVENT_RUN_BEGIN, () => {
process.stdout.write(colors.yellow('\u00B7'));
});
}
});
total += runner.grepTotal(mocha.suite);

rootSuite.addSuite(mocha.suite);
mocha.suite.title = path.basename(file);
}

// Now run the tests.
if (rootSuite.hasOnly())
rootSuite.filterOnly();
console.log();
total = Math.min(total, rootSuite.total()); // First accounts for grep, second for only.
console.log(`Running ${total} tests using ${Math.min(command.jobs, total)} workers`);
if (!command.reporter) {
console.log();
total = Math.min(total, rootSuite.total()); // First accounts for grep, second for only.
console.log(`Running ${total} tests using ${Math.min(command.jobs, total)} workers`);
}

const runner = new Runner(rootSuite, {
// Trial run does not need many workers, use one.
const jobs = command.trialRun ? 1 : command.jobs;
const runner = new Runner(rootSuite, jobs, {
grep: command.grep,
jobs: command.jobs,
reporter: command.reporter,
retries: command.retries,
timeout: command.timeout,
trialRun: command.trialRun,
});
await runner.run(files);
await runner.stop();
Expand Down
4 changes: 2 additions & 2 deletions test/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const constants = Mocha.Runner.constants;
process.setMaxListeners(0);

class Runner extends EventEmitter {
constructor(suite, options) {
constructor(suite, jobs, options) {
super();
this._suite = suite;
this._jobs = jobs;
this._options = options;
this._jobs = options.jobs;
this._workers = new Set();
this._freeWorkers = [];
this._workerClaimers = [];
Expand Down
2 changes: 1 addition & 1 deletion test/runner/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let failedWithError = false;
async function runSingleTest(file, options) {
let lastOrdinal = -1;
const mocha = new Mocha({
ui: fixturesUI.bind(null, false),
ui: fixturesUI.bind(null, options.trialRun),
timeout: options.timeout,
reporter: NullReporter
});
Expand Down