-
Notifications
You must be signed in to change notification settings - Fork 7
/
runtests.js
64 lines (53 loc) · 1.65 KB
/
runtests.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
53
54
55
56
57
58
59
60
61
62
63
64
/*global phantom:true console:true console_reporter:true */
// Runs a Jasmine Suite from an html page
// @page is a PhantomJs page object
// @exit_func is the function to call in order to exit the script
(function(phantom, WebPage){
"use strict";
var PhantomJasmineRunner = function(page, exit_func){
this.page = page;
this.exit_func = exit_func || phantom.exit;
this.tries = 0;
this.max_tries = 10;
this.get_status = function(){
return this.page.evaluate(function(){
return console_reporter.status;
});
};
this.terminate = function(){
var status = this.get_status();
if (status === 'success') {
this.exit_func(0);
} else if (status === 'fail') {
this.exit_func(1);
} else {
this.exit_func(2);
}
};
};
// Script Begin
if (phantom.args.length === 0) {
console.log("Need a url as the argument");
phantom.exit(1);
}
var page = new WebPage();
var runner = new PhantomJasmineRunner(page);
var address = phantom.args[0];
// Don't supress console output
page.onConsoleMessage = function(msg){
console.log(msg);
// Terminate when the reporter singals that testing is over.
// We cannot use a callback function for this (because page.evaluate is sandboxed),
// so we have to *observe* the website.
if (msg == "ConsoleReporter finished") {
runner.terminate();
}
};
page.open(address, function(status){
if (status != "success") {
console.log("can't load the address!");
phantom.exit(1);
}
// Now we wait until onConsoleMessage reads the termination signal from the log.
});
}(phantom, WebPage));