Skip to content

Commit

Permalink
Fixed nightwatchjs#1289 RangeError: "Maximum call stack size exceeded…
Browse files Browse the repository at this point in the history
…", occuring when a test setting value is set to null
  • Loading branch information
plusgut authored and beatfactor committed Dec 14, 2016
1 parent f3bc41c commit d0ee441
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/runner/cli/clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CliRunner.prototype = {
// reading the settings file
try {
this.settings = require(this.argv.config);
this.replaceEnvVariables();
this.replaceEnvVariables(this.settings);

this.manageSelenium = !this.isParallelMode() && this.settings.selenium &&
this.settings.selenium.start_process || false;
Expand All @@ -109,16 +109,15 @@ CliRunner.prototype = {
* @param {Object} [target]
*/
replaceEnvVariables : function(target) {
target = target || this.settings;
for (var key in target) {
switch(typeof target[key]) {
case 'object':
this.replaceEnvVariables(target[key]);
case 'object':
this.replaceEnvVariables(target[key]);
break;
case 'string':
target[key] = target[key].replace(/\$\{(\w+)\}/g, function(match, varName) {
return process.env[varName] || '${' + varName + '}';
});
case 'string':
target[key] = target[key].replace(/\$\{(\w+)\}/g, function(match, varName) {
return process.env[varName] || '${' + varName + '}';
});
break;
}
}
Expand Down
33 changes: 33 additions & 0 deletions test/src/runner/cli/testCliRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,27 @@ module.exports = {
}, 'No testing environment specified.');
},

testParseTestSettingsNull : function() {
mockery.registerMock('fs', {
statSync : function(module) {
if (module == './null.json') {
return {isFile : function() {return true;}};
}
throw new Error('Does not exist');
}
});

var CliRunner = common.require('runner/cli/clirunner.js');

var runner = new CliRunner({
config : './null.json',
env : 'default'
});
runner.init();
assert.ok(typeof runner.settings.test_settings == 'object');
assert.strictEqual(runner.settings.test_settings['default'].irrelevantProperty, null);
},

testParseTestSettingsIncorrect : function() {
mockery.registerMock('fs', {
statSync : function(module) {
Expand Down Expand Up @@ -708,6 +729,15 @@ module.exports = {
src_folders : 'tests'
});

mockery.registerMock('./null.json', {
src_folders : 'tests',
test_settings : {
'default' : {
irrelevantProperty: null
}
}
});

mockery.registerMock('./incorrect.json', {
src_folders : 'tests',
test_settings : {
Expand Down Expand Up @@ -849,6 +879,9 @@ module.exports = {
if (b == './empty.json') {
return './empty.json';
}
if (b == './null.json') {
return './null.json';
}
if (b == './incorrect.json') {
return './incorrect.json';
}
Expand Down

0 comments on commit d0ee441

Please sign in to comment.