This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
/
testrunner.js
52 lines (52 loc) · 1.82 KB
/
testrunner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
console.log('Loading: test.html');
var page = require('webpage').create();
var url = 'index.html';
page.open(url, function (status) {
if (status === 'success') {
setTimeout(function () {
var results = page.evaluate(function() {
// remove the first node with the total from the following counts
var passed = Math.max(0, document.querySelectorAll('.pass').length - 1);
return {
// retrieve the total executed tests number
total: ''.concat(
passed,
' blocks (',
document.querySelector('#wru strong').textContent.replace(/\D/g, ''),
' single tests)'
),
passed: passed,
failed: Math.max(0, document.querySelectorAll('.fail').length - 1),
failures: [].map.call(document.querySelectorAll('.fail'), function (node) {
return node.textContent;
}),
errored: Math.max(0, document.querySelectorAll('.error').length - 1),
errors: [].map.call(document.querySelectorAll('.error'), function (node) {
return node.textContent;
})
};
});
console.log('- - - - - - - - - -');
console.log('total: ' + results.total);
console.log('- - - - - - - - - -');
console.log('passed: ' + results.passed);
if (results.failed) {
console.log('failures: \n' + results.failures.join('\n'));
} else {
console.log('failed: ' + results.failed);
}
if (results.errored) {
console.log('errors: \n' + results.errors.join('\n'));
} else {
console.log('errored: ' + results.errored);
}
console.log('- - - - - - - - - -');
if (0 < results.failed + results.errored) {
status = 'failed';
}
phantom.exit(0);
}, 3000);
} else {
phantom.exit(1);
}
});