commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / bower_components / qunit / addons / phantomjs / runner.js
1 /*
2 * Qt+WebKit powered headless test runner using Phantomjs
3 *
4 * Phantomjs installation: http://code.google.com/p/phantomjs/wiki/BuildInstructions
5 *
6 * Run with:
7 * phantomjs runner.js [url-of-your-qunit-testsuite]
8 *
9 * E.g.
10 * phantomjs runner.js http://localhost/qunit/test
11 */
12
13 var url = phantom.args[0];
14
15 var page = require('webpage').create();
16
17 // Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
18 page.onConsoleMessage = function(msg) {
19 console.log(msg);
20 };
21
22 page.onInitialized = function() {
23 page.evaluate(addLogging);
24 };
25 page.open(url, function(status){
26 if (status !== "success") {
27 console.log("Unable to access network: " + status);
28 phantom.exit(1);
29 } else {
30 // page.evaluate(addLogging);
31 var interval = setInterval(function() {
32 if (finished()) {
33 clearInterval(interval);
34 onfinishedTests();
35 }
36 }, 500);
37 }
38 });
39
40 function finished() {
41 return page.evaluate(function(){
42 return !!window.qunitDone;
43 });
44 }
45
46 function onfinishedTests() {
47 var output = page.evaluate(function() {
48 return JSON.stringify(window.qunitDone);
49 });
50 phantom.exit(JSON.parse(output).failed > 0 ? 1 : 0);
51 }
52
53 function addLogging() {
54 window.document.addEventListener( "DOMContentLoaded", function() {
55 var current_test_assertions = [];
56
57 QUnit.testDone(function(result) {
58 var name = result.module + ': ' + result.name;
59 var i;
60
61 if (result.failed) {
62 console.log('Assertion Failed: ' + name);
63
64 for (i = 0; i < current_test_assertions.length; i++) {
65 console.log(' ' + current_test_assertions[i]);
66 }
67 }
68
69 current_test_assertions = [];
70 });
71
72 QUnit.log(function(details) {
73 var response;
74
75 if (details.result) {
76 return;
77 }
78
79 response = details.message || '';
80
81 if (typeof details.expected !== 'undefined') {
82 if (response) {
83 response += ', ';
84 }
85
86 response += 'expected: ' + details.expected + ', but was: ' + details.actual;
87 }
88
89 current_test_assertions.push('Failed assertion: ' + response);
90 });
91
92 QUnit.done(function(result){
93 console.log('Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.');
94 window.qunitDone = result;
95 });
96 }, false );
97 }