Skip to content

Commit

Permalink
Fixes/run mocha on child process workers (#3904)
Browse files Browse the repository at this point in the history
* use child process in mocha runner

* added test
  • Loading branch information
gravityvi authored Sep 4, 2023
1 parent 0822095 commit 863d2c9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/runner/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ class CliRunner {
}

setupConcurrency() {

if (this.testRunner?.type === Runner.MOCHA_RUNNER) {
this.test_settings.use_child_process = true;
}

this.concurrency = new Concurrency(this.test_settings, this.argv, this.isTestWorkersEnabled());

return this;
Expand Down
44 changes: 44 additions & 0 deletions test/src/cli/testCliRunnerMocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('test CLI Runner Mocha', function() {
resolve: function(a) {
return a;
},
extname: path.extname,
join: path.join
});

Expand Down Expand Up @@ -89,6 +90,49 @@ describe('test CLI Runner Mocha', function() {
});
});

it('testRunWithMocha - parallelism', function() {

const ChildProcess = common.require('runner/concurrency/child-process.js');
let childProcessCreated = false;
class ChildProcessMock extends ChildProcess {
run(colors, type) {
childProcessCreated = true;
assert.strictEqual(colors.length, 4);
assert.strictEqual(type, 'workers');
assert.deepStrictEqual(Object.keys(this._events), ['message']);

return Promise.resolve(0);
}
}

mockery.registerMock('./child-process.js', ChildProcessMock);

mockery.registerMock('./withmocha.json', {
src_folders: ['tests'],
output_folder: false,
use_child_process: false,
test_settings: {
'default': {
silent: true
}
},
test_runner: 'mocha'
});


const CliRunner = common.require('runner/cli/cli.js');
const runner = new CliRunner({
config: './withmocha.json',
env: 'default',
reporter: 'junit',
parallel: true
}).setup();

return runner.runTests().then(function() {
assert.ok(childProcessCreated, 'mocha runner with parallel threads should use child process');
});
});

it('testRunWithMochaPerEnvironment', function() {
const testFiles = [];
const defaultOptions = {timeout: 20000, reporterOptions: {}};
Expand Down

0 comments on commit 863d2c9

Please sign in to comment.