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

Feature/disable process listener for programattic api #3800

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
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports.createClient = function({
debug = false,
enable_global_apis = false,
config = './nightwatch.json',
disable_process_listener = false,
test_settings
} = {}) {
if (browserName && !env) {
Expand Down Expand Up @@ -73,7 +74,8 @@ module.exports.createClient = function({
timeout,
devtools,
debug,
parallel
parallel,
disable_process_listener
});

const settings = arguments[0] || {};
Expand Down
9 changes: 7 additions & 2 deletions lib/runner/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ class CliRunner {
this.globals = null;
this.testEnv = null;
this.testEnvArray = [];
this.processListener = new ProcessListener();

if (!argv.disable_process_listener) {
this.processListener = new ProcessListener();
}
}

initTestSettings(userSettings = {}, baseSettings = null, argv = null, testEnv = '', asyncLoading) {
Expand Down Expand Up @@ -452,7 +455,9 @@ class CliRunner {
globalsInstance: this.globals
});

this.processListener.setTestRunner(this.testRunner);
if (this.processListener) {
this.processListener.setTestRunner(this.testRunner);
}

return this;
}
Expand Down
70 changes: 70 additions & 0 deletions test/src/index/testProgrammaticApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,74 @@ describe('test programmatic apis', function () {
CliRunner.createDefaultConfig = createDefaultConfig;
CliRunner.prototype.loadConfig = loadConfig;
});

it('test if process listener get disabled', async function() {
let processListenerCalled = false;
mockery.enable({useCleanCache: true, warnOnUnregistered: false});
mockery.registerMock('../process-listener.js', class {
constructor() {
processListenerCalled = true;
}

setTestRunner() {}
});

const CliRunner = common.require('runner/cli/cli.js');
const Nightwatch = common.require('index.js');

const createDefaultConfig = CliRunner.createDefaultConfig;
const loadConfig = CliRunner.prototype.loadConfig;
const defaultConfig = {
test_settings: {
default: {
launchUrl: 'http://localhost'
}
},
selenium: {
port: 10195,
start_process: false
},
selenium_host: 'localhost'
};

CliRunner.createDefaultConfig = function(destFileName) {
return defaultConfig;
};

CliRunner.prototype.loadConfig = function () {
return defaultConfig;
};

const clientWithoutListner = Nightwatch.createClient({
timeout: 500,
useAsync: false,
output: false,
silent: false,
headless: true,
output_folder: 'output',
globals: {
testGlobal: 'one'
},
disable_process_listener: true
});

assert.ok(!processListenerCalled);

const client = Nightwatch.createClient({
timeout: 500,
useAsync: false,
output: false,
silent: false,
headless: true,
output_folder: 'output',
globals: {
testGlobal: 'one'
}
});

assert.ok(processListenerCalled);

CliRunner.createDefaultConfig = createDefaultConfig;
CliRunner.prototype.loadConfig = loadConfig;
});
});