Skip to content

Commit

Permalink
improved the console output for parallel execution
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed May 11, 2014
1 parent d9abec7 commit 97eb5d2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
53 changes: 44 additions & 9 deletions bin/_clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ CliRunner.prototype = {
this.startSelenium(function() {
Runner.run(source, self.test_settings, {
output_folder : self.output_folder,
src_folders : self.settings.src_folders
src_folders : self.settings.src_folders,
live_output : self.settings.live_output
}, function(err) {
self
.stopSelenium()
Expand Down Expand Up @@ -350,7 +351,7 @@ CliRunner.prototype = {
if (!this.manageSelenium) {
return this;
}
this.settings.cli_args = {};
this.settings.selenium.cli_args = {};

var deprecationNotice = function(propertyName, newSettingName) {
console.warn(Logger.colors.brown('DEPRECATION NOTICE: Property ' + propertyName + ' is deprecated since v0.5. Please' +
Expand Down Expand Up @@ -390,7 +391,7 @@ CliRunner.prototype = {
var self = this;

this.startSelenium(function() {
self.startChildProcesses(envs, function() {
self.startChildProcesses(envs, function(o) {
self.stopSelenium();
});
});
Expand Down Expand Up @@ -442,10 +443,35 @@ CliRunner.prototype = {
availColors[randomIndex] = temporaryValue;
}

var prevIndex = 0;
var output = {};
var writeToSdtout = function(data, item, index) {
data = data.replace(/^\s+|\s+$/g, '');
output[item] = output[item] || [];

var env_output = '';
var color_pair = availColors[index%4];
process.stdout.write(Logger.colors[color_pair[1]]('[' + item + ']', Logger.colors.background[color_pair[0]]) + '\t' + data + '\n');
if (prevIndex !== index) {
prevIndex = index;
if (self.settings.live_output) {
env_output += '\n';
}
}

env_output += Logger.colors[color_pair[1]](' ' + item + ' ',
Logger.colors.background[color_pair[0]]);

if (self.settings.live_output) {
env_output += ' ' + data;
} else {
env_output += '\t' + data + '\n';
}

if (self.settings.live_output) {
console.log(env_output);
} else {
output[item].push(env_output);
}
};

envs.forEach(function(item, index) {
Expand All @@ -460,9 +486,10 @@ CliRunner.prototype = {
cwd : process.cwd(),
encoding: 'utf8',
env : env
}, function (error, stdout, stderr) {
}, function (error, stdout, stderr) {});

});
console.log('Started child process for env:',
Logger.colors.yellow(' ' + item + ' ', Logger.colors.background.black), '\n');

child.stdout.on('data', function (data) {
writeToSdtout(data, item, index);
Expand All @@ -473,13 +500,21 @@ CliRunner.prototype = {
});

child.on('close', function (code) {
if (index == envs.length - 1) {
finishCallback();
if (!self.settings.live_output) {
var child_output = output[item];
for (var i = 0; i < child_output.length; i++) {
process.stdout.write(child_output[i]);
}
console.log('');
}

if (index === (envs.length - 1)) {
finishCallback(output);
}
});
}, index * 10);
});
}
};

module.exports = CliRunner;
module.exports = CliRunner;
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Nightwatch.prototype.printResult = function(startTime) {
if (this.results.failed === 0 && this.results.errors === 0) {
ok = true;
}

process.stdout.write('\n');
var elapsedTime = new Date().getTime() - startTime;
if (ok && this.results.passed > 0) {
console.log(Logger.colors.green('OK.'),
Expand Down
17 changes: 12 additions & 5 deletions lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ module.exports = new (function() {
}

if (opts.output) {
console.log('Running: ', Logger.colors.green(currentTest), '\n');
process.stdout.write('\n');
console.log((opts.parallelMode && !opts.live_output ? 'Results for: ' : 'Running: '),
Logger.colors.green(currentTest), '\n');
}
var localStartTime = new Date().getTime();
var test = wrapTest(setUp, tearDown, module[currentTest], module, function(results, errors) {
Expand Down Expand Up @@ -193,8 +195,10 @@ module.exports = new (function() {

function printResults(testresults, modulekeys) {
var elapsedTime = new Date().getTime() - globalStartTime;
process.stdout.write('\n');
if (testresults.passed > 0 && testresults.errors === 0 && testresults.failed === 0) {
console.log(Logger.colors.green('\nOK. ' + testresults.passed, Logger.colors.background.black), 'total assertions passed. (' + elapsedTime + ' ms)');
console.log(Logger.colors.green('OK. ' + testresults.passed, Logger.colors.background.black),
'total assertions passed. (' + elapsedTime + ' ms)');
} else {
var skipped = '';
if (testresults.skipped) {
Expand All @@ -205,9 +209,9 @@ module.exports = new (function() {
return Logger.colors.cyan('"' + e + '"');
});
var plural = modulekeys.length > 1 ? 's' : '';
skipped += '\nStep' + plural + ' ' + modulekeys.join(', ') + ' skipped.';
skipped += 'Step' + plural + ' ' + modulekeys.join(', ') + ' skipped.';
}
console.log(Logger.colors.light_red('\nTEST FAILURE:'), Logger.colors.red(testresults.errors + testresults.failed) +
console.log(Logger.colors.light_red('TEST FAILURE:'), Logger.colors.red(testresults.errors + testresults.failed) +
' assertions failed, ' + Logger.colors.green(testresults.passed) + ' passed' + skipped, '(' + elapsedTime + ' ms)');
}
}
Expand Down Expand Up @@ -395,6 +399,8 @@ module.exports = new (function() {
*/
this.run = function runner(test_source, opts, additional_opts, finishCallback) {
opts.parallelMode = process.env.__NIGHTWATCH_PARALLEL_MODE == '1';
opts.live_output = additional_opts.live_output;

opts.report_prefix = '';

globalStartTime = new Date().getTime();
Expand Down Expand Up @@ -433,7 +439,8 @@ module.exports = new (function() {
globalResults.modules[moduleName] = [];

if (opts.output) {
var testSuiteName = 'Running ' + getTestSuiteName(moduleName) + ' Test Suite';
var testSuiteName = (opts.parallelMode && !opts.live_output ? '' : 'Running ') +
getTestSuiteName(moduleName) + ' Test Suite';
console.log('\n' + Logger.colors.light_green(testSuiteName));
console.log(Logger.colors.purple(new Array(testSuiteName.length + 1).join('=')));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runner/selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = new (function() {
if (data.toString().indexOf(SENTINEL) != -1) {
seleniumProcess.removeListener('exit', exitHandler);
util.print(Logger.colors.light_purple('started - PID: ' ) + ' ' +
seleniumProcess.pid + '\n');
seleniumProcess.pid + '\n' + (settings.parallelMode ? '\n' : ''));
callback(null, seleniumProcess);
}
});
Expand Down

0 comments on commit 97eb5d2

Please sign in to comment.