-
Notifications
You must be signed in to change notification settings - Fork 153
/
unit-test.js
52 lines (42 loc) · 1.19 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
var system = require('system');
var url,args;
if (phantom.version.major > 1) {
args = system.args;
if (args.length < 2) {
system.stderr.write('Expected a target URL parameter.');
phantom.exit(1);
}
url = args[1];
} else {
args = phantom.args;
if (args.length < 1) {
system.stderr.write('Expected a target URL parameter.');
phantom.exit(1);
}
url = args[0];
}
var page = require('webpage').create();
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);
});