Add chalk to test/saucelabs.js.

This commit is contained in:
John-David Dalton
2014-03-20 20:57:37 -07:00
parent 1bab2061bd
commit 7d54cde8eb

View File

@@ -6,7 +6,7 @@
var env = process.env; var env = process.env;
if (isFinite(env.TRAVIS_PULL_REQUEST)) { if (isFinite(env.TRAVIS_PULL_REQUEST)) {
console.error('Skipping Sauce Labs jobs for pull requests'); console.log('Skipping Sauce Labs jobs for pull requests');
process.exit(0); process.exit(0);
} }
@@ -18,6 +18,7 @@
/** Load other modules */ /** Load other modules */
var _ = require('../lodash.js'), var _ = require('../lodash.js'),
chalk = require('chalk'),
ecstatic = require('ecstatic'), ecstatic = require('ecstatic'),
request = require('request'), request = require('request'),
SauceTunnel = require('sauce-tunnel'); SauceTunnel = require('sauce-tunnel');
@@ -181,6 +182,10 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
function capitalizeWords(string) {
return _.map(string.split(' '), _.capitalize).join(' ');
}
/** /**
* Gets the value for the given option name. If no value is available the * Gets the value for the given option name. If no value is available the
* `defaultValue` is returned. * `defaultValue` is returned.
@@ -262,35 +267,39 @@
} }
function onCheck(error, response, body) { function onCheck(error, response, body) {
var completed = _.result(body, 'completed'), var data = _.result(body, 'js tests', [{}])[0],
data = _.result(body, 'js tests', [{ 'status': 'test error' }])[0], options = this.options,
platform = JSON.stringify(this.options.platforms[0]), platform = options.platforms[0],
result = data.result, result = data.result,
failures = _.result(result, 'failed'); completed = _.result(body, 'completed'),
description = capitalizeWords(platform[1].replace('google', '')) + ' ' + platform[2] + ' on ' + capitalizeWords(platform[0]),
failures = _.result(result, 'failed'),
label = options.name + ':';
if (!completed) { if (!completed) {
setTimeout(check.bind(this), statusInterval); setTimeout(check.bind(this), statusInterval);
return; return;
} }
if (!result || failures || reError.test(result.message)) { if (!result || failures || reError.test(result.message)) {
if (this.attempts < maxRetries) { if (this.attempts <= maxRetries) {
this.attempts++; this.attempts++;
console.log(label + ' attempt %d', this.attempts);
this.run(); this.run();
return; return;
} }
_.assign(this, data, { 'failed': true }); _.assign(this, data, { 'failed': true });
var details = 'See ' + this.url + ' for details.';
var details = 'See ' + this.url + ' for details.',
message = _.result(result, 'message', 'no results available. ' + details);
logInline(''); logInline('');
if (failures) { if (failures) {
console.error('There was %d failures on %s. %s', failures, platform, details); console.error(label + ' %s ' + chalk.red('failed') + ' %d test' + (failures > 1 ? 's' : '') + '. %s', description, failures, details);
} else { } else {
console.error('Testing on %s failed; %s', platform, message); var message = _.result(result, 'message', 'no results available. ' + details);
console.error(label, description, chalk.red('failed') + ';', message);
} }
} else { } else {
console.log('Testing on %s passed', platform); console.log(label, description, chalk.green('passed'));
} }
this.emit('complete'); this.emit('complete');
} }
@@ -350,7 +359,7 @@
} }
}); });
console.log('Starting jobs %s', JSON.stringify(_.omit(defaultOptions, 'platforms'), null, 2)); console.log('Starting jobs...');
_.invoke(jobs, 'run'); _.invoke(jobs, 'run');
} }