$(function(){ 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++; }); } /* 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 */ var WebdriverAndHtmlReporter = function(html_reporter){ return function(runner){ Base.call(this, 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","[green]PASSED[clear] :", test.title); } else if (test.pending) { append("->","[yellow]PENDING[clear]:", test.title); } else { append("->","[red]FAILED[clear] :", test.title, stringifyException(test.err)); } if(killTimeout) clearTimeout(killTimeout); killTimeout = setTimeout(function(){ append("FINISHED - [red]no test started since 3 minutes, tests stopped[clear]"); }, 60000 * 3); }); var total = runner.total; runner.on('end', function(){ if(stats.tests >= total){ var minutes = Math.floor(stats.duration / 1000 / 60); var seconds = Math.round((stats.duration / 1000) % 60); append("FINISHED -", stats.passes, "tests passed,", stats.failures, "tests failed, duration: " + minutes + ":" + seconds); } }); $(window).on('error', function(e){ append("[red]Uncaught Javascript Error:[clear]", stringifyException(e)); }) } } //allow cross iframe access if ((!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf("1.8.") == 0))) { document.domain = document.domain; // for comet } //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 var specs = specs_list.slice(); //inject spec scripts into the dom var $body = $('body'); $.each(specs, function(i, spec){ $body.append('') }); //initalize the test helper helper.init(function(){ //configure and start the test framework var grep = getURLParameter("grep"); if(grep != "null"){ mocha.grep(grep); } mocha.ignoreLeaks(); mocha.reporter(WebdriverAndHtmlReporter(mocha._reporter)); mocha.run(); }); });