File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ // Run tests in PhantomJS
2+ //
3+ // Exits with status code 0 is all tests pass, or 1 if any fail.
4+ // Pipes successful assertions to stdout and errors to stderr
5+ //
6+ // Run with $ phantomjs TestRunner.js
7+ //
8+ var page = require ( 'webpage' ) . create ( ) ;
9+ page . open ( './test.html' , function ( ) {
10+
11+ // get an array, with as the first element the test strings and second the test results
12+ var testOutput = page . evaluate ( function ( ) {
13+ return document . getElementById ( 'test-output' ) . textContent . split ( 'Tests: ' ) ;
14+ } ) ;
15+
16+ var passed = testOutput [ 0 ] . match ( / ✔ [ ^ ✔ ✘ ] * / g) || [ ] ;
17+ for ( var i = 0 ; i < passed . length ; i ++ ) {
18+ console . log ( passed [ i ] ) ;
19+ }
20+
21+ var failed = testOutput [ 0 ] . match ( / ✘ [ ^ ✔ ✘ ] * / g) || [ ] ;
22+ for ( var j = 0 ; j < failed . length ; j ++ ) {
23+ console . error ( failed [ j ] ) ;
24+ }
25+
26+ console . log ( 'Tests: ' + testOutput [ 1 ] ) ;
27+ phantom . exit ( failed . length ? 1 : 0 ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments