Skip to content

Commit

Permalink
Feature/disable process listener for programattic api (#3800)
Browse files Browse the repository at this point in the history
* disable programattic api for process listners

* refactor and add tests
  • Loading branch information
swrdfish authored Jul 19, 2023
1 parent f7999e8 commit 54e1e3e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
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;
});
});

0 comments on commit 54e1e3e

Please sign in to comment.