]> git.proxmox.com Git - mirror_novnc.git/blob - tests/run_from_console.casper.js
Switch to PhantomJS 2.x for testing
[mirror_novnc.git] / tests / run_from_console.casper.js
1 var Spooky = require('spooky');
2 var path = require('path');
3
4 var phantom_path = require('phantomjs-prebuilt').path;
5 var casper_path = path.resolve(__dirname, '../node_modules/casperjs/bin/casperjs');
6 process.env.PHANTOMJS_EXECUTABLE = phantom_path;
7 var casper_opts = {
8 child: {
9 transport: 'http',
10 command: casper_path
11 },
12 casper: {
13 logLevel: 'debug',
14 verbose: true
15 }
16 };
17
18 var provide_emitter = function(file_paths, debug_port) {
19 if (debug_port) {
20 casper_opts.child['remote-debugger-port'] = debug_port;
21 var debug_url = ('https://localhost:' + debug_port +
22 '/webkit/inspector/inspector.html?page=');
23 console.info('[remote-debugger] Navigate to ' + debug_url + '1 and ' +
24 'run `__run();` in the console to continue loading.' +
25 '\n[remote-debugger] Navigate to ' + debug_url + '2 to ' +
26 'view the actual page source.\n' +
27 '[remote-debugger] Use the `debugger;` statement to ' +
28 'trigger an initial breakpoint.');
29 }
30
31 var spooky = new Spooky(casper_opts, function(err) {
32 if (err) {
33 if (err.stack) console.warn(err.stack);
34 else console.warn(err);
35 return;
36 }
37 spooky.start('about:blank');
38
39 file_paths.forEach(function(file_path, path_ind) {
40 spooky.thenOpen('file://'+file_path);
41 spooky.waitFor(function() {
42 return this.getGlobal('__mocha_done') === true;
43 },
44 [{ path_ind: path_ind }, function() {
45 var res_json = {
46 file_ind: path_ind
47 };
48
49 res_json.num_tests = this.evaluate(function() { return document.querySelectorAll('li.test').length; });
50 res_json.num_passes = this.evaluate(function() { return document.querySelectorAll('li.test.pass').length; });
51 res_json.num_fails = this.evaluate(function() { return document.querySelectorAll('li.test.fail').length; });
52 res_json.num_slow = this.evaluate(function() { return document.querySelectorAll('li.test.pass:not(.fast):not(.pending)').length; });
53 res_json.num_skipped = this.evaluate(function () { return document.querySelectorAll('li.test.pending').length; });
54 res_json.duration = this.evaluate(function() { return document.querySelector('li.duration em').textContent; });
55
56 res_json.suites = this.evaluate(function() {
57 var traverse_node = function(elem) {
58 var res;
59 if (elem.classList.contains('suite')) {
60 res = {
61 type: 'suite',
62 name: elem.querySelector('h1').textContent,
63 has_subfailures: elem.querySelectorAll('li.test.fail').length > 0,
64 };
65
66 var child_elems = elem.querySelector('ul').children;
67 res.children = Array.prototype.map.call(child_elems, traverse_node);
68 return res;
69 }
70 else {
71 var h2_content = elem.querySelector('h2').childNodes;
72 res = {
73 type: 'test',
74 text: h2_content[0].textContent,
75 };
76
77 if (elem.classList.contains('pass')) {
78 res.pass = true;
79 if (elem.classList.contains('pending')) {
80 res.slow = false;
81 res.skipped = true;
82 }
83 else {
84 res.slow = !elem.classList.contains('fast');
85 res.skipped = false;
86 res.duration = h2_content[1].textContent;
87 }
88 }
89 else {
90 res.error = elem.querySelector('pre.error').textContent;
91 }
92
93 return res;
94 }
95 };
96 var top_suites = document.querySelectorAll('#mocha-report > li.suite');
97 return Array.prototype.map.call(top_suites, traverse_node);
98 });
99
100 res_json.replay = this.evaluate(function() { return document.querySelector('a.replay').textContent; });
101
102 this.emit('test_ready', res_json);
103 }]);
104 });
105 spooky.run();
106 });
107
108 return spooky;
109 };
110
111 module.exports = {
112 provide_emitter: provide_emitter,
113 name: 'SpookyJS (CapserJS on PhantomJS)'
114 };