-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathunit-test.js
39 lines (30 loc) · 928 Bytes
/
unit-test.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
if (phantom.args.length != 1) {
console.log('Expected a target URL parameter.');
phantom.exit(1);
}
var page = require('webpage').create();
var url = phantom.args[0];
page.onConsoleMessage = function (message) {
console.log("Test console: " + message);
};
console.log("Loading URL: " + url);
page.open(url, function (status) {
if (status != "success") {
console.log('Failed to open ' + url);
phantom.exit(1);
}
console.log("Running test.");
var result = page.evaluate(function() {
return example.test.run();
});
// NOTE: PhantomJS 1.4.0 has a bug that prevents the exit codes
// below from being returned properly. :(
//
// http://code.google.com/p/phantomjs/issues/detail?id=294
if (result != 0) {
console.log("*** Test failed! ***");
phantom.exit(1);
}
console.log("Test succeeded.");
phantom.exit(0);
});