Make use of the wait throbber in quint and cleanup the throbber in saucelabs.js.

This commit is contained in:
John-David Dalton
2013-11-15 22:18:03 -08:00
parent bca3ff2eac
commit 7a4103dd48
2 changed files with 77 additions and 24 deletions

View File

@@ -17,9 +17,13 @@
request = require('request'),
SauceTunnel = require('sauce-tunnel');
/** Used by `logInline` */
var attempts = -1,
prevLine = '';
/** Used by `logInline` to clear previously logged messages */
var prevLine = '';
/** Used to display the wait throbber */
var throbberId,
throbberDelay = 500,
waitCount = -1;
/** Used as request `auth` and `options` values */
var port = 8081,
@@ -131,6 +135,15 @@
process.stdout.write(text + blankLine.slice(text.length) + '\r');
}
/**
* Writes the wait throbber to standard output.
*
* @private
*/
function logThrobber() {
logInline('Please wait' + repeat('.', (++waitCount % 3) + 1));
}
/**
* Converts a comma separated option value into an array.
*
@@ -208,6 +221,7 @@
});
}
clearInterval(throbberId);
console.log('Shutting down Sauce Connect tunnel...');
tunnel.stop(function() {
@@ -250,6 +264,12 @@
process.exit(3);
}
});
// initialize the wait throbber
if (!throbberId) {
throbberId = setInterval(logThrobber, throbberDelay);
logThrobber();
}
}
/**
@@ -272,7 +292,6 @@
handleTestResults(body['js tests']);
}
else {
logInline('Please wait' + repeat('.', (++attempts % 3) + 1));
setTimeout(function() {
waitForTestCompletion(testIdentifier);
}, 5000);

View File

@@ -30,6 +30,29 @@
return;
}
/** Used to report the test module for failing tests */
var moduleName,
modulePrinted;
/** Used to display the wait throbber */
var throbberId,
throbberDelay = 500,
waitCount = -1;
/** Add `console.log()` support for Narwhal, Rhino, and RingoJS */
var console = context.console || (context.console = { 'log': context.print });
/** Used as a horizontal rule in console output */
var hr = '----------------------------------------';
/** Used by `logInline` to clear previously logged messages */
var prevLine = '';
/** Shorten `context.QUnit.QUnit` to `context.QUnit` */
var QUnit = context.QUnit = context.QUnit.QUnit || context.QUnit;
/*------------------------------------------------------------------------*/
/**
* Schedules timer-based callbacks.
*
@@ -108,24 +131,8 @@
/*------------------------------------------------------------------------*/
/** Used to report the test module for failing tests */
var moduleName,
modulePrinted;
/** Add `console.log()` support for Narwhal, Rhino, and RingoJS */
var console = context.console || (context.console = { 'log': context.print });
/** Used as a horizontal rule in console output */
var hr = '----------------------------------------';
/** Used by `logInline` to clear previously logged messages */
var prevLine = '';
/** Shorten `context.QUnit.QUnit` to `context.QUnit` */
var QUnit = context.QUnit = context.QUnit.QUnit || context.QUnit;
/**
* Logs an inline message to standard output.
* Writes an inline message to standard output.
*
* @private
* @param {string} text The text to log.
@@ -142,7 +149,7 @@
process.exit();
});
return function(text) {
var blankLine = Array(prevLine.length + 1).join(' ');
var blankLine = repeat(' ', prevLine.length);
if (text.length > hr.length) {
text = text.slice(0, hr.length - 3) + '...';
}
@@ -151,6 +158,29 @@
}
}());
/**
* Writes the wait throbber to standard output.
*
* @private
*/
function logThrobber() {
logInline('Please wait' + repeat('.', (++waitCount % 3) + 1));
}
/**
* Creates a string with `text` repeated `n` number of times.
*
* @private
* @param {string} text The text to repeat.
* @param {number} n The number of times to repeat `text`.
* @returns {string} The created string.
*/
function repeat(text, n) {
return Array(n + 1).join(text);
}
/*------------------------------------------------------------------------*/
/**
* A logging callback triggered when all testing is completed.
*
@@ -224,11 +254,17 @@
* @param {Object} details An object with property `name`.
*/
QUnit.moduleStart(function(details) {
// reset the `modulePrinted` flag
var newModuleName = details.name;
if (moduleName != newModuleName) {
moduleName = newModuleName;
modulePrinted = false;
}
// initialize the wait throbber
if (!throbberId) {
throbberId = context.setInterval(logThrobber, throbberDelay);
logThrobber();
}
});
/**
@@ -275,8 +311,6 @@
assertions.forEach(function(value) {
console.log(' ' + value);
});
} else {
logInline('Testing ' + moduleName + '...');
}
assertions.length = 0;
});