]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/run_from_console.casper.js
1 var Spooky
= require('spooky');
2 var path
= require('path');
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
;
18 var provide_emitter = function(file_paths
, 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.');
31 var spooky
= new Spooky(casper_opts
, function(err
) {
33 if (err
.stack
) console
.warn(err
.stack
);
34 else console
.warn(err
);
37 spooky
.start('about:blank');
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;
44 [{ path_ind
: path_ind
}, function() {
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
; });
56 res_json
.suites
= this.evaluate(function() {
57 var traverse_node = function(elem
) {
59 if (elem
.classList
.contains('suite')) {
62 name
: elem
.querySelector('h1').textContent
,
63 has_subfailures
: elem
.querySelectorAll('li.test.fail').length
> 0,
66 var child_elems
= elem
.querySelector('ul').children
;
67 res
.children
= Array
.prototype.map
.call(child_elems
, traverse_node
);
71 var h2_content
= elem
.querySelector('h2').childNodes
;
74 text
: h2_content
[0].textContent
,
77 if (elem
.classList
.contains('pass')) {
79 if (elem
.classList
.contains('pending')) {
84 res
.slow
= !elem
.classList
.contains('fast');
86 res
.duration
= h2_content
[1].textContent
;
90 res
.error
= elem
.querySelector('pre.error').textContent
;
96 var top_suites
= document
.querySelectorAll('#mocha-report > li.suite');
97 return Array
.prototype.map
.call(top_suites
, traverse_node
);
100 res_json
.replay
= this.evaluate(function() { return document
.querySelector('a.replay').textContent
; });
102 this.emit('test_ready', res_json
);
112 provide_emitter
: provide_emitter
,
113 name
: 'SpookyJS (CapserJS on PhantomJS)'