@@ -29,12 +29,12 @@ const glob = require('glob');
29
29
const path = require ( 'path' ) ;
30
30
31
31
const TEST_FILES = glob . sync ( path . resolve (
32
- __dirname ,
33
- '../../test/com/google/javascript/jscomp/runtime_tests/**/build/*_test.html'
32
+ __dirname ,
33
+ '../../test/com/google/javascript/jscomp/runtime_tests/**/build/*_test.html' ,
34
34
) ) ;
35
35
36
36
describe ( 'Runtime tests' , ( ) => {
37
- for ( let testUrl of TEST_FILES ) {
37
+ for ( const testUrl of TEST_FILES ) {
38
38
const logs = [ ] ;
39
39
const passed = / P A S S E D / i;
40
40
const failed = / F A I L E D / i;
@@ -43,37 +43,36 @@ describe('Runtime tests', () => {
43
43
const chalkMsg = ( msg ) => {
44
44
const isPass = passed . test ( msg ) ;
45
45
const isFail = failed . test ( msg ) ;
46
-
46
+
47
47
if ( isPass || isFail ) {
48
48
return msg . replace (
49
- passed , chalk . green ( 'PASSED' )
49
+ passed , chalk . green ( 'PASSED' ) ,
50
50
) . replace (
51
- failed , chalk . red ( 'FAILED' )
51
+ failed , chalk . red ( 'FAILED' ) ,
52
52
) ;
53
- }
54
- else return msg ;
55
- }
56
-
53
+ } else return msg ;
54
+ } ;
55
+
57
56
const testName = path . basename ( testUrl ) ;
58
57
const TestIsFinished = new FutureEvent ( ) ;
59
58
const virtualConsole = new VirtualConsole ( )
60
- . on ( 'log' , ( msg ) => {
61
- logs . push ( chalkMsg ( msg ) ) ;
62
- if ( / T e s t s c o m p l e t e / i. test ( msg ) ) TestIsFinished . ready ( allLogs ( ) ) ;
63
- else if ( / T e s t s f a i l e d / i. test ( msg ) ) TestIsFinished . cancel ( allLogs ( ) ) ;
64
- } ) ;
59
+ . on ( 'log' , ( msg ) => {
60
+ logs . push ( chalkMsg ( msg ) ) ;
61
+ if ( / T e s t s c o m p l e t e / i. test ( msg ) ) TestIsFinished . ready ( allLogs ( ) ) ;
62
+ else if ( / T e s t s f a i l e d / i. test ( msg ) ) TestIsFinished . cancel ( allLogs ( ) ) ;
63
+ } ) ;
65
64
66
65
const TEST_DOC = fs . readFileSync (
67
- path . resolve (
68
- __dirname ,
69
- '../../' ,
70
- testUrl
71
- ) ,
72
- 'utf-8'
66
+ path . resolve (
67
+ __dirname ,
68
+ '../../' ,
69
+ testUrl ,
70
+ ) ,
71
+ 'utf-8' ,
73
72
) ;
74
73
75
74
it ( `should pass test suite ${ path . basename ( testUrl ) } ` , async ( ) => {
76
- const { window } = new JSDOM ( TEST_DOC , {
75
+ new JSDOM ( TEST_DOC , {
77
76
/**
78
77
* This does not actually run a server of any kind, it only informs the
79
78
* DOM what to put in `window.location.origin`. By default, this is
@@ -90,23 +89,15 @@ describe('Runtime tests', () => {
90
89
/**
91
90
* Pipe `console.log` to our virtual console.
92
91
*/
93
- virtualConsole
92
+ virtualConsole,
94
93
} ) ;
95
94
96
95
try {
97
96
await TestIsFinished ;
98
97
} catch ( e ) {
99
- // Format the error a bit: first line red, rest unformatted.
100
- const errorLines = e . toString ( ) . split ( '\n' ) ;
101
- let formattedError ;
102
- for ( let i = 0 ; i < errorLines . length ; i ++ ) {
103
- formattedError += i === 0
104
- ? chalk . red ( errorLines [ i ] )
105
- : errorLines [ i ] ;
106
- }
107
- fail ( `Failed test in suite ${ testName } : \n${ formattedError } \n` ) ;
98
+ fail ( `Failed test in suite ${ testName } : \n${ e } \n` ) ;
108
99
}
109
100
console . log ( `Passed all tests in suite ${ testName } ` ) ;
110
101
} ) ;
111
102
}
112
- } ) ;
103
+ } ) ;
0 commit comments