2012-10-03 18:37:48 +02:00
|
|
|
$(function(){
|
2012-11-03 15:31:33 +01:00
|
|
|
function Base(runner) {
|
|
|
|
var self = this
|
|
|
|
, stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
|
|
|
|
, failures = this.failures = [];
|
|
|
|
|
|
|
|
if (!runner) return;
|
|
|
|
this.runner = runner;
|
|
|
|
|
|
|
|
runner.on('start', function(){
|
|
|
|
stats.start = new Date;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('suite', function(suite){
|
|
|
|
stats.suites = stats.suites || 0;
|
|
|
|
suite.root || stats.suites++;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('test end', function(test){
|
|
|
|
stats.tests = stats.tests || 0;
|
|
|
|
stats.tests++;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('pass', function(test){
|
|
|
|
stats.passes = stats.passes || 0;
|
|
|
|
|
|
|
|
var medium = test.slow() / 2;
|
|
|
|
test.speed = test.duration > test.slow()
|
|
|
|
? 'slow'
|
|
|
|
: test.duration > medium
|
|
|
|
? 'medium'
|
|
|
|
: 'fast';
|
|
|
|
|
|
|
|
stats.passes++;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('fail', function(test, err){
|
|
|
|
stats.failures = stats.failures || 0;
|
|
|
|
stats.failures++;
|
|
|
|
test.err = err;
|
|
|
|
failures.push(test);
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('end', function(){
|
|
|
|
stats.end = new Date;
|
|
|
|
stats.duration = new Date - stats.start;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('pending', function(){
|
|
|
|
stats.pending++;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-10-28 14:22:30 +01:00
|
|
|
/*
|
|
|
|
This reporter wraps the original html reporter plus reports plain text into a hidden div.
|
|
|
|
This allows the webdriver client to pick up the test results
|
|
|
|
*/
|
2012-10-28 14:16:41 +01:00
|
|
|
var WebdriverAndHtmlReporter = function(html_reporter){
|
|
|
|
return function(runner){
|
2012-11-03 15:31:33 +01:00
|
|
|
Base.call(this, runner);
|
2012-11-18 12:49:34 +01:00
|
|
|
|
|
|
|
// Scroll down test display after each test
|
|
|
|
mocha = $('#mocha')[0];
|
|
|
|
runner.on('test', function(){
|
|
|
|
mocha.scrollTop = mocha.scrollHeight;
|
|
|
|
});
|
|
|
|
|
2012-10-28 14:16:41 +01:00
|
|
|
//initalize the html reporter first
|
|
|
|
html_reporter(runner);
|
|
|
|
|
|
|
|
var $console = $("#console");
|
|
|
|
var level = 0;
|
|
|
|
var append = function(){
|
|
|
|
var text = Array.prototype.join.apply(arguments, [" "]);
|
|
|
|
var oldText = $console.text();
|
|
|
|
|
|
|
|
var space = "";
|
|
|
|
for(var i=0;i<level*2;i++){
|
|
|
|
space+=" ";
|
|
|
|
}
|
|
|
|
|
2012-11-03 19:14:54 +01:00
|
|
|
var splitedText = "";
|
|
|
|
_(text.split("\n")).each(function(line){
|
|
|
|
while(line.length > 0){
|
|
|
|
var split = line.substr(0,100);
|
|
|
|
line = line.substr(100);
|
|
|
|
if(splitedText.length > 0) splitedText+="\n";
|
|
|
|
splitedText += split;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-28 14:16:41 +01:00
|
|
|
//indent all lines with the given amount of space
|
2012-11-03 19:14:54 +01:00
|
|
|
var newText = _(splitedText.split("\n")).map(function(line){
|
2012-10-28 14:16:41 +01:00
|
|
|
return space + line;
|
2012-11-03 18:02:28 +01:00
|
|
|
}).join("\\n");
|
2012-10-28 14:16:41 +01:00
|
|
|
|
2012-11-03 18:02:28 +01:00
|
|
|
$console.text(oldText + newText + "\\n");
|
2012-10-28 14:16:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
runner.on('suite', function(suite){
|
|
|
|
if (suite.root) return;
|
|
|
|
|
|
|
|
append(suite.title);
|
|
|
|
level++;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('suite end', function(suite){
|
|
|
|
if (suite.root) return;
|
|
|
|
level--;
|
|
|
|
|
|
|
|
if(level == 0) {
|
|
|
|
append("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-03 15:31:33 +01:00
|
|
|
var stringifyException = function(exception){
|
|
|
|
var err = exception.stack || exception.toString();
|
|
|
|
|
|
|
|
// FF / Opera do not add the message
|
|
|
|
if (!~err.indexOf(exception.message)) {
|
|
|
|
err = exception.message + '\n' + err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
|
|
|
|
// check for the result of the stringifying.
|
|
|
|
if ('[object Error]' == err) err = exception.message;
|
|
|
|
|
|
|
|
// Safari doesn't give you a stack. Let's at least provide a source line.
|
|
|
|
if (!exception.stack && exception.sourceURL && exception.line !== undefined) {
|
|
|
|
err += "\n(" + exception.sourceURL + ":" + exception.line + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-11-03 17:51:37 +01:00
|
|
|
var killTimeout;
|
2012-10-28 14:16:41 +01:00
|
|
|
runner.on('test end', function(test){
|
|
|
|
if ('passed' == test.state) {
|
2012-11-03 14:20:44 +01:00
|
|
|
append("->","[green]PASSED[clear] :", test.title);
|
2012-10-28 14:16:41 +01:00
|
|
|
} else if (test.pending) {
|
2012-11-03 14:20:44 +01:00
|
|
|
append("->","[yellow]PENDING[clear]:", test.title);
|
2012-10-28 14:16:41 +01:00
|
|
|
} else {
|
2012-11-03 15:31:33 +01:00
|
|
|
append("->","[red]FAILED[clear] :", test.title, stringifyException(test.err));
|
2012-10-28 14:16:41 +01:00
|
|
|
}
|
2012-11-03 17:51:37 +01:00
|
|
|
|
|
|
|
if(killTimeout) clearTimeout(killTimeout);
|
|
|
|
killTimeout = setTimeout(function(){
|
|
|
|
append("FINISHED - [red]no test started since 3 minutes, tests stopped[clear]");
|
|
|
|
}, 60000 * 3);
|
2012-10-28 14:16:41 +01:00
|
|
|
});
|
|
|
|
|
2012-11-03 15:31:33 +01:00
|
|
|
var total = runner.total;
|
2012-10-28 14:16:41 +01:00
|
|
|
runner.on('end', function(){
|
2012-11-03 15:31:33 +01:00
|
|
|
if(stats.tests >= total){
|
|
|
|
var minutes = Math.floor(stats.duration / 1000 / 60);
|
|
|
|
var seconds = Math.round((stats.duration / 1000) % 60);
|
|
|
|
|
2012-11-03 15:56:34 +01:00
|
|
|
append("FINISHED -", stats.passes, "tests passed,", stats.failures, "tests failed, duration: " + minutes + ":" + seconds);
|
2012-11-03 15:31:33 +01:00
|
|
|
}
|
2012-10-28 14:16:41 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 18:50:59 +02:00
|
|
|
//http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery
|
|
|
|
var getURLParameter = function (name) {
|
|
|
|
return decodeURI(
|
|
|
|
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//get the list of specs and filter it if requested
|
2012-10-27 18:05:26 +02:00
|
|
|
var specs = specs_list.slice();
|
2012-10-27 18:50:59 +02:00
|
|
|
|
|
|
|
//inject spec scripts into the dom
|
|
|
|
var $body = $('body');
|
2012-10-27 18:05:26 +02:00
|
|
|
$.each(specs, function(i, spec){
|
2013-02-04 01:03:25 +01:00
|
|
|
if(spec[0] != "/"){ // if the spec isn't a plugin spec which means the spec file might be in a different subfolder
|
|
|
|
$body.append('<script src="specs/' + spec + '"></script>')
|
|
|
|
}else{
|
|
|
|
$body.append('<script src="' + spec + '"></script>')
|
|
|
|
}
|
2012-10-27 18:05:26 +02:00
|
|
|
});
|
|
|
|
|
2012-10-03 18:37:48 +02:00
|
|
|
//initalize the test helper
|
2012-10-08 00:34:29 +02:00
|
|
|
helper.init(function(){
|
2013-12-05 08:41:29 +01:00
|
|
|
//configure and start the test framework
|
2012-10-27 18:50:59 +02:00
|
|
|
var grep = getURLParameter("grep");
|
|
|
|
if(grep != "null"){
|
|
|
|
mocha.grep(grep);
|
|
|
|
}
|
2012-10-28 14:16:41 +01:00
|
|
|
|
2013-12-05 08:41:29 +01:00
|
|
|
mocha.ignoreLeaks();
|
|
|
|
|
2012-10-28 14:16:41 +01:00
|
|
|
mocha.reporter(WebdriverAndHtmlReporter(mocha._reporter));
|
|
|
|
|
|
|
|
mocha.run();
|
2012-10-08 00:34:29 +02:00
|
|
|
});
|
2013-02-04 01:03:25 +01:00
|
|
|
});
|