diff --git a/lib/index.js b/lib/index.js index 27d78e7349..7bc09bbf68 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { @@ -73,7 +74,8 @@ module.exports.createClient = function({ timeout, devtools, debug, - parallel + parallel, + disable_process_listener }); const settings = arguments[0] || {}; diff --git a/lib/runner/cli/cli.js b/lib/runner/cli/cli.js index 0048f4f279..bc42fffc46 100644 --- a/lib/runner/cli/cli.js +++ b/lib/runner/cli/cli.js @@ -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) { @@ -452,7 +455,9 @@ class CliRunner { globalsInstance: this.globals }); - this.processListener.setTestRunner(this.testRunner); + if (this.processListener) { + this.processListener.setTestRunner(this.testRunner); + } return this; } diff --git a/test/src/index/testProgrammaticApis.js b/test/src/index/testProgrammaticApis.js index 27b2307e38..f281e54be9 100644 --- a/test/src/index/testProgrammaticApis.js +++ b/test/src/index/testProgrammaticApis.js @@ -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; + }); });