2012-10-03 18:37:48 +02:00
|
|
|
$(function(){
|
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){
|
|
|
|
//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+=" ";
|
|
|
|
}
|
|
|
|
|
|
|
|
//indent all lines with the given amount of space
|
|
|
|
var newText = _(text.split("\n")).map(function(line){
|
|
|
|
return space + line;
|
|
|
|
}).join("\n");
|
|
|
|
|
|
|
|
$console.text(oldText + newText + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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 {
|
|
|
|
var err = test.err.stack || test.err.toString();
|
|
|
|
|
|
|
|
// FF / Opera do not add the message
|
|
|
|
if (!~err.indexOf(test.err.message)) {
|
|
|
|
err = test.err.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 = test.err.message;
|
|
|
|
|
|
|
|
// Safari doesn't give you a stack. Let's at least provide a source line.
|
|
|
|
if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) {
|
|
|
|
err += "\n(" + test.err.sourceURL + ":" + test.err.line + ")";
|
|
|
|
}
|
|
|
|
|
2012-11-03 14:20:44 +01:00
|
|
|
append("->","[red]","FAILED :", test.title, err, "[clear]");
|
2012-10-28 14:16:41 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('end', function(){
|
|
|
|
append("FINISHED");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:37:48 +02:00
|
|
|
//allow cross iframe access
|
2012-10-08 00:34:29 +02:00
|
|
|
if ((!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf("1.8.") == 0))) {
|
|
|
|
document.domain = document.domain; // for comet
|
|
|
|
}
|
2012-10-02 01:35:43 +02: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){
|
|
|
|
$body.append('<script src="specs/' + spec + '"></script>')
|
|
|
|
});
|
|
|
|
|
2012-10-03 18:37:48 +02:00
|
|
|
//initalize the test helper
|
2012-10-08 00:34:29 +02:00
|
|
|
helper.init(function(){
|
|
|
|
//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
|
|
|
|
2012-10-08 00:34:29 +02: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
|
|
|
});
|
2012-10-28 22:21:17 +01:00
|
|
|
});
|