easy-bake
Version:
EasyBake provides an efficient environment for CoffeeScript library developers: CoffeeScript/Javascript-based configuration files (no coding needed), workflow (build, watch, clean, preview) tests (QUnit, Jasime, NodeUnit, server-side emulation with ModuleBundler), publishing (git, npm, NuGet). Replace your Cakefile with a Bakefile today!
88 lines (83 loc) • 2.66 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var args, e, page, page_filename, silent, start, timeout,
_this = this;
try {
args = phantom.args;
if (args.length < 1 || args.length > 3) {
console.log("Usage: " + phantom.scriptName + " <URL> <timeout> <silent>");
phantom.exit(1);
}
page_filename = args[0];
timeout = parseInt(args[1], 10) || 60000;
silent = args.length >= 2 ? !!args[2] : false;
start = Date.now();
page = require('webpage').create();
page.onConsoleMessage = function(msg) {
if (msg.indexOf('warning') !== 0) {
return console.log(msg);
}
};
page.onInitialized = function() {
return page.evaluate(function() {
return window.MochaReporter = (function() {
function MochaReporter(runner) {
var _this = this;
this.failedCount = 0;
this.totalCount = 0;
runner.on('pass', function(test) {
return _this.totalCount++;
});
runner.on('fail', function(test, err) {
_this.failedCount++;
return _this.totalCount++;
});
runner.on('end', function() {
console.log("tests end: " + (_this.totalCount - _this.failedCount) + "/" + _this.totalCount);
return window.mocha_results = {
totalCount: _this.totalCount,
failedCount: _this.failedCount
};
});
}
return MochaReporter;
})();
});
};
page.open(page_filename, function(status) {
var interval;
if (status !== 'success') {
console.error("Unable to access network");
return phantom.exit(1);
} else {
return interval = setInterval((function() {
var code, stats;
if (Date.now() > start + timeout) {
console.error("Tests timed out");
return phantom.exit(124);
} else {
if (!(stats = page.evaluate(function() {
return window.mocha_results;
}))) {
return;
}
clearInterval(interval);
if (stats.totalCount <= 0) {
phantom.exit(-1);
return;
}
code = stats.failedCount > 0 ? 1 : 0;
if (!silent) {
console.log("phantomjs-mocha-runner.js: exiting (" + code + ")");
}
return phantom.exit(code);
}
}), 500);
}
});
} catch (_error) {
e = _error;
console.error("Mocha exception: " + e);
phantom.exit(1);
}
}).call(this);