Skip to content

Commit

Permalink
added initial test for parallel execution
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Sep 22, 2014
1 parent 9ddece0 commit 77026a4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 8 deletions.
5 changes: 4 additions & 1 deletion bin/_clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ CliRunner.prototype = {
});
return this;
}

this.settings.parallelMode = this.parallelMode;
var self = this;

Expand Down Expand Up @@ -253,13 +254,14 @@ CliRunner.prototype = {
* Starts the test runner
* @returns {CliRunner}
*/
runTests : function() {
runTests : function(callback) {
if (this.parallelMode) {
return this;
}

var source = this.getTestSource();
var self = this;

this.startSelenium(function() {
Runner.run(source, self.test_settings, {
output_folder : self.output_folder,
Expand All @@ -272,6 +274,7 @@ CliRunner.prototype = {
var context = self.test_settings && self.test_settings.globals || null;
afterGlobal.call(context, function() {
self.globalErrorHandler(err);
callback();
});

});
Expand Down
30 changes: 30 additions & 0 deletions tests/extra/nightwatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"src_folders" : ["./sampletests"],
"output_folder" : "./output",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"globals_path" : "",

"selenium" : {
"start_process" : false,
"server_path" : "./bin/selenium-server.jar"
},

"test_settings" : {
"default" : {
"silent" : true,
"desiredCapabilities" : {
"browserName" : "firefox",
"javascriptEnabled" : true,
"acceptSslCerts" : true
},
"filter" : ["async/*"]
},

"mixed" : {
"filter" : ["mixed/*"]
}
}
}


15 changes: 8 additions & 7 deletions tests/run_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ try {
var server = require('mockserver').init();
server.on('listening', function() {
reporter.run([
'src',
'src/index',
'src/runner',
'src/assertions',
'src/commands',
'src/protocol',
'src/http'
//'src',
//'src/index',
'src/cli',
// 'src/runner',
// 'src/assertions',
// 'src/commands',
// 'src/protocol',
// 'src/http'
], options, function(err) {
server.close();
if (err) {
Expand Down
59 changes: 59 additions & 0 deletions tests/src/cli/testParallelExecution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var BASE_PATH = process.env.NIGHTWATCH_COV
? 'lib-cov'
: 'lib';
var util = require('util');
var events = require('events');
var mockery = require('mockery');
module.exports = {
setUp: function(callback) {
mockery.enable({ useCleanCache: true, warnOnUnregistered: true });
callback();
},

tearDown: function(callback) {
callback();
},

testParallelExecution : function(test) {
var allArgs = [], allOpts = [];
mockery.registerMock('child_process', {
execFile : function(path, args, opts) {
allArgs.push(args);
allOpts.push(opts);

function Stdout() {}
function Stderr() {}

util.inherits(Stdout, events.EventEmitter);
util.inherits(Stderr, events.EventEmitter);

var Child = function() {
this.stdout = new Stdout();
this.stderr = new Stderr();
};

util.inherits(Child, events.EventEmitter);
return new Child();
}
});

mockery.registerMock('../lib/runner/run.js', {
run : function(source, settings, opts, callback) {
console.log('Run', source, settings)
//callback();
}
});

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

runner.runTests(function() {
console.log(allArgs);
console.log(allOpts);
test.done();
});
}
};

0 comments on commit 77026a4

Please sign in to comment.