21
21
*/
22
22
23
23
const { JSDOM , VirtualConsole } = require ( 'jsdom' ) ;
24
+ const { fail } = require ( 'assert' ) ;
25
+ const chalk = require ( 'chalk' ) ;
24
26
const fs = require ( 'fs' ) ;
25
- const path = require ( 'path' ) ;
26
27
const FutureEvent = require ( 'future-event' ) ;
27
- const { fail } = require ( 'assert' ) ;
28
28
const glob = require ( 'glob' ) ;
29
+ const path = require ( 'path' ) ;
29
30
30
31
const TEST_FILES = glob . sync ( path . resolve (
31
32
__dirname ,
@@ -35,13 +36,29 @@ const TEST_FILES = glob.sync(path.resolve(
35
36
describe ( 'Runtime tests' , ( ) => {
36
37
for ( const TEST_URL of TEST_FILES ) {
37
38
const logs = [ ] ;
39
+ const passed = / P A S S E D / i;
40
+ const failed = / F A I L E D / i;
41
+
38
42
const allLogs = ( ) => logs . join ( '\n' ) ;
43
+ const chalkMsg = ( msg ) => {
44
+ const isPass = passed . test ( msg ) ;
45
+ const isFail = failed . test ( msg ) ;
46
+
47
+ if ( isPass || isFail ) {
48
+ return msg . replace (
49
+ passed , chalk . green ( 'PASSED' )
50
+ ) . replace (
51
+ failed , chalk . red ( 'FAILED' )
52
+ ) ;
53
+ }
54
+ else return msg ;
55
+ }
39
56
40
57
const TEST_NAME = path . basename ( TEST_URL ) ;
41
58
const TestIsFinished = new FutureEvent ( ) ;
42
59
const virtualConsole = new VirtualConsole ( )
43
60
. on ( 'log' , ( msg ) => {
44
- logs . push ( msg ) ;
61
+ logs . push ( chalkMsg ( msg ) ) ;
45
62
if ( / T e s t s c o m p l e t e / i. test ( msg ) ) TestIsFinished . ready ( allLogs ( ) ) ;
46
63
else if ( / T e s t s f a i l e d / i. test ( msg ) ) TestIsFinished . cancel ( allLogs ( ) ) ;
47
64
} ) ;
@@ -65,9 +82,9 @@ describe('Runtime tests', () => {
65
82
try {
66
83
await TestIsFinished ;
67
84
} catch ( e ) {
68
- fail ( `Failed test in suite ${ TEST_NAME } : \n\n ${ e } ` ) ;
85
+ fail ( `Failed test in suite ${ TEST_NAME } : \n${ e } \n ` ) ;
69
86
}
70
87
console . log ( `Passed all tests in suite ${ TEST_NAME } ` ) ;
71
- } ) ;
88
+ } , 20000 ) ;
72
89
}
73
90
} ) ;
0 commit comments