Skip to content

Commit

Permalink
improved tests and read globals external
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed May 16, 2014
1 parent f00b092 commit f15977c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 8 deletions.
14 changes: 10 additions & 4 deletions bin/_clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ CliRunner.prototype = {
try {
var fullPath = path.resolve(this.settings.globals_path);
if (fs.existsSync(fullPath)) {
var globals = require(fullPath);
var globals = this.test_settings.globals = require(fullPath);
if (globals && globals.hasOwnProperty(this.argv.e)) {
this.test_settings.globals = globals[this.argv.e];
for (var prop in globals[this.argv.e]) {
this.test_settings.globals[prop] = globals[this.argv.e][prop];
}
}
return this;
}
Expand Down Expand Up @@ -138,7 +140,9 @@ CliRunner.prototype = {
err.message = 'There was an error while running the test.';
}

console.error(Logger.colors.red(err.message));
if (this.test_settings.output) {
console.error(Logger.colors.red(err.message));
}

process.exit(1);
}
Expand Down Expand Up @@ -207,7 +211,9 @@ CliRunner.prototype = {
var self = this;
Selenium.startServer(this.settings, function(error, child, error_out, exitcode) {
if (error) {
Logger.error('There was an error while starting the Selenium server:');
if (self.test_settings.output) {
Logger.error('There was an error while starting the Selenium server:');
}
self.globalErrorHandler({
message : error_out
});
Expand Down
88 changes: 84 additions & 4 deletions tests/src/runner/testCliRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ module.exports = {
}
});

mockery.registerMock('./globals.json', {
extra : {
someGlobal : 'test'
},
otherGlobal : 'other-value'
});

mockery.registerMock('./settings.json', {
src_folders : 'tests',
test_settings : {
Expand Down Expand Up @@ -300,10 +307,7 @@ module.exports = {
testParseTestSettingsIncorrect : function(test) {
mockery.registerMock('fs', {
existsSync : function(module) {
if (module == './incorrect.json') {
return true;
}
return false;
return module == './incorrect.json';
}
});

Expand All @@ -316,5 +320,81 @@ module.exports = {
}, 'Invalid testing environment specified: incorrect');

test.done();
},

testReadExternalGlobals : function(test) {
mockery.registerMock('fs', {
existsSync : function(module) {
if (module == './custom.json' || module == './globals.json') {
return true;
}
return false;
}
});

var CliRunner = require('../../../'+ BASE_PATH +'/../bin/_clirunner.js');
var runner = new CliRunner({
c : './custom.json',
e : 'extra'
}).init();

runner.settings.globals_path = './globals.json';
runner.readExternalGlobals();

test.equals(runner.test_settings.globals.otherGlobal, 'other-value');
test.equals(runner.test_settings.globals.someGlobal, 'test');


test.throws(function() {
var runner = new CliRunner({
c : './custom.json',
e : 'extra'
}).init();
runner.settings.globals_path = './incorrect.json';
runner.readExternalGlobals();

}, 'External global file could not be located - using ./incorrect.json.');

test.done();
},

testStartSeleniumDisabled : function(test) {
var CliRunner = require('../../../'+ BASE_PATH +'/../bin/_clirunner.js');
var runner = new CliRunner({
c : './nightwatch.json',
e : 'default'
}).init();

runner.manageSelenium = false;
test.expect(1);
runner.startSelenium(function() {
test.ok('callback called');
test.done();
});
},

testStartSeleniumEnabled : function(test) {
mockery.registerMock('../lib/runner/selenium.js', {
startServer : function(settings, cb) {
cb({}, null, 'Server already running.');
}
});
var CliRunner = require('../../../'+ BASE_PATH +'/../bin/_clirunner.js');
var runner = new CliRunner({
c : './nightwatch.json',
e : 'default'
}).init();

runner.manageSelenium = true;
runner.parallelMode = true;
test.expect(2);

runner.globalErrorHandler = function(err) {
test.equals(err.message, 'Server already running.');
test.equals(runner.settings.parallelMode, true);
test.done();
};

runner.startSelenium();
}
};

0 comments on commit f15977c

Please sign in to comment.