1 // Invoke via: ./test
.sh
3 // or phantomjs phantom-driver.js [testCase.test]
5 // For more on phantomjs, visit www.phantomjs.org.
7 var page
= require('webpage').create();
9 // NOTE: Cannot include '#' or '?' in this URL.
10 var url
= 'auto_tests/misc/local.html';
12 // NOTE: changing the line below to this:
13 // page.open(url, function(status)) {
14 // makes phantomjs hang.
15 page
.open(url
, function(status
) {
16 if (status
!== 'success') {
17 console
.warn('Page status: ' + status
);
23 if (phantom
.args
.length
== 1) {
24 var parts
= phantom
.args
[0].split('.');
25 if (2 != parts
.length
) {
26 console
.warn('Usage: phantomjs phantom-driver.js [testCase.test]');
33 var loggingOn
= false;
34 page
.onConsoleMessage
= function (msg
) {
35 if (msg
== 'Running ' + test
) {
37 } else if (msg
.substr(0, 'Running'.length
) == 'Running') {
40 if (loggingOn
) console
.log(msg
);
43 page
.onError
= function (msg
, trace
) {
45 trace
.forEach(function(item
) {
46 console
.log(' ', item
.file
, ':', item
.line
);
53 var start
= new Date().getTime();
54 results
= page
.evaluate(function() {
55 // Phantom doesn't like stacktrace.js using the "arguments" object
56 // in stacktrace.js, which it interprets in strict mode.
57 printStackTrace
= undefined
;
59 var testCases
= getAllTestCases();
61 for (var idx
in testCases
) {
62 var entry
= testCases
[idx
];
64 var prototype = entry
.testCase
;
65 var tc
= new entry
.testCase();
66 var result
= tc
.runAllTests();
67 results
[entry
.name
] = result
;
71 var end
= new Date().getTime();
72 var elapsed
= (end
- start
) / 1000;
74 var num_passing
= 0, num_failing
= 0;
76 for (var testCase
in results
) {
77 var caseResults
= results
[testCase
];
78 for (var test
in caseResults
) {
79 if (caseResults
[test
] !== true) {
81 failures
.push(testCase
+ '.' + test
+ ' failed');
83 // console.log(testCase + '.' + test + ' passed');
89 console
.log('Ran ' + (num_passing
+ num_failing
) + ' tests in ' + elapsed
+ 's.');
90 console
.log(num_passing
+ ' test(s) passed');
91 console
.log(num_failing
+ ' test(s) failed:');
92 for (var i
= 0; i
< failures
.length
; i
++) {
93 // TODO(danvk): print an auto_test/misc/local URL that runs
this test
.
94 console
.log(' ' + failures
[i
] + ' failed.');
97 if (num_failing
== 0) {