Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/run mocha on child process workers #3904

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
25 changes: 15 additions & 10 deletions lib/runner/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CliRunner {
static get CONFIG_FILE_TS() {
return './nightwatch.conf.ts';
}

static createDefaultConfig(destFileName) {
// eslint-disable-next-line no-console
console.log(Logger.colors.cyan('No config file found in the current working directory, creating nightwatch.conf.js in the current folder...'));
Expand Down Expand Up @@ -149,7 +149,7 @@ class CliRunner {
}
}
}

setMobileOptions(argv) {
const {desiredCapabilities, selenium = {}} = this.test_settings;

Expand Down Expand Up @@ -194,7 +194,7 @@ class CliRunner {

if (!this.baseSettings) {
return this;
}
}

this.availableTestEnvs = Object.keys(this.baseSettings.test_settings).filter(key => {
return Utils.isObject(this.baseSettings.test_settings[key]);
Expand Down Expand Up @@ -262,7 +262,7 @@ class CliRunner {
test_workers_enabled: this.test_settings.testWorkersEnabled,
use_xpath: this.test_settings.use_xpath,
is_bstack: this.test_settings.desiredCapabilities['bstack:options'] !== undefined,
test_runner: this.test_settings.test_runner ? this.test_settings.test_runner.type : null
test_runner: this.test_settings.test_runner ? this.test_settings.test_runner.type : null
});
}

Expand Down Expand Up @@ -297,7 +297,7 @@ class CliRunner {
if (usingTS) {
return path.resolve(CliRunner.CONFIG_FILE_TS);
}

return path.resolve(CliRunner.CONFIG_FILE_JS);
}

Expand Down Expand Up @@ -402,13 +402,13 @@ class CliRunner {
for (const env of this.testEnvArray) {
const {webdriver = {}} = this.testEnvSettings[env];
const desiredCapabilities = this.testEnvSettings[env].capabilities || this.testEnvSettings[env].desiredCapabilities;

if (isMobile(desiredCapabilities)) {

if (Concurrency.isWorker()) {
Logger.info('Disabling parallelism while running tests on mobile platform');
}

return false;
}

Expand All @@ -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 Expand Up @@ -492,7 +497,7 @@ class CliRunner {
return this.runGlobalHook('before', [this.test_settings])
.then(_ => {
return this.runGlobalHook('beforeChildProcess', [this.test_settings], true);
})
})
.then(_ => {
return this.getTestsFiles();
})
Expand Down Expand Up @@ -628,7 +633,7 @@ class CliRunner {
}

analyticsCollector.__flush();

return errorOrFailed;
});
}
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