@@ -28,12 +28,19 @@ const FutureEvent = require('future-event');
2828const glob = require ( 'glob' ) ;
2929const path = require ( 'path' ) ;
3030
31+ /**
32+ * All test files in the test.com.google.javascript.jscomp.runtime_tests.build
33+ * directory.
34+ */
3135const TEST_FILES = glob . sync ( path . resolve (
3236 __dirname ,
3337 '../../test/com/google/javascript/jscomp/'
3438 + 'runtime_tests/**/build/*_test.html' ,
3539) ) ;
3640
41+ /**
42+ * Iterate over all found test files and execute them in JSDOM.
43+ */
3744describe ( 'Runtime tests' , ( ) => {
3845 for ( const testFile of TEST_FILES ) {
3946 const logs = [ ] ;
@@ -42,31 +49,47 @@ describe('Runtime tests', () => {
4249
4350 const allLogs = ( ) => logs . join ( '\n' ) ;
4451 const chalkMsg = ( msg ) => {
52+ /**
53+ * Check whether or not this message is a PASSED or FAILED message.
54+ */
4555 const isPass = passed . test ( msg ) ;
4656 const isFail = failed . test ( msg ) ;
4757
48- if ( isPass || isFail ) {
49- return msg . replace (
50- passed , chalk . green ( 'PASSED' ) ,
51- ) . replace (
52- failed , chalk . red ( 'FAILED' ) ,
53- ) ;
54- } else return msg ;
58+ /**
59+ * Highlight PASSED and FAILED in messages to help with accessibility.
60+ */
61+ return ( isPass || isFail )
62+ ? msg
63+ . replace ( passed , chalk . green ( 'PASSED' ) )
64+ . replace ( failed , chalk . red ( 'FAILED' ) )
65+ : msg ;
5566 } ;
5667
57- // file.ext -> file
68+ /**
69+ * Get filename, i.e. /path/to/file.ext -> file.ext
70+ */
5871 const testName = path . basename ( testFile ) ;
59- // A promise that will resolve when JSDOM is done executing.
72+
73+ /**
74+ * A promise that will resolve when JSDOM is done executing.
75+ */
6076 const testIsFinished = new FutureEvent ( ) ;
61- // A virtual console which will receive messages from JSDOM's `console.log`.
77+
78+ /**
79+ * A virtual console which will receive messages from JSDOM's
80+ * `console.log`.
81+ */
6282 const virtualConsole = new VirtualConsole ( )
6383 . on ( 'log' , ( msg ) => {
6484 logs . push ( chalkMsg ( msg ) ) ;
6585 if ( / T e s t s c o m p l e t e / i. test ( msg ) ) testIsFinished . ready ( allLogs ( ) ) ;
6686 else if ( / T e s t s f a i l e d / i. test ( msg ) ) testIsFinished . cancel ( allLogs ( ) ) ;
6787 } ) ;
6888
69- // Load the generated test file for consumption by the JSDOM environment.
89+ /**
90+ * Load the generated test file for consumption by the JSDOM environment.
91+ * This will be a raw HTML document.
92+ */
7093 const testDocument = fs . readFileSync (
7194 path . resolve (
7295 __dirname ,
@@ -81,8 +104,9 @@ describe('Runtime tests', () => {
81104 /**
82105 * This does not actually run a server of any kind, it only informs the
83106 * DOM what to put in `window.location.origin`. By default, this is
84- * `null`, and any non-HTTPS URL field here will throw an error in the
85- * test suite due to unsafe URL.
107+ * `null`, which throws an "unsafe URL" error in the test suite. This is
108+ * purely for accurately mocking a browser for `goog.testing.testsuite`
109+ * tests, and any valid HTTPS URL will work here.
86110 */
87111 url : 'https://localhost:42' ,
88112 /**
@@ -98,13 +122,19 @@ describe('Runtime tests', () => {
98122 } ) ;
99123
100124 try {
101- // Wait for test to finish.
125+ /**
126+ * Wait for test to finish, resume if no errors thrown.
127+ */
102128 await testIsFinished ;
103129 } catch ( e ) {
104- // If there was an error, print it.
130+ /**
131+ * Print error and fail if any occurred.
132+ */
105133 fail ( `Failed test in suite ${ testName } : \n${ e } \n` ) ;
106134 }
107- // Otherwise, everything passed.
135+ /**
136+ * Otherwise, everything passed.
137+ */
108138 console . log ( `Passed all tests in suite ${ testName } ` ) ;
109139 } ) ;
110140 }
0 commit comments