@@ -35,21 +35,35 @@ const qunitChromeRunner = (
3535
3636 return new Promise ( ( resolve , reject ) => {
3737 ( async ( ) => {
38+ const closeBrowser = async ( browser , rejection ) => {
39+ try {
40+ await browser . close ( ) ;
41+ } catch ( ex ) {
42+ log ( ) ;
43+ log ( chalk . yellow ( "Failed to close Chromium." ) ) ;
44+ log ( ) ;
45+ }
46+
47+ if ( rejection ) {
48+ reject ( rejection ) ;
49+ }
50+ } ;
51+
52+ log ( "Testing" , chalk . magenta ( fixturePath ) ) ;
53+
54+ const browser = await puppeteer . launch ( { headless : false } ) ;
55+ const page = await browser . newPage ( ) ;
56+ const failures = [ ] ;
57+
3858 // Setting our timeout in case everything below takes too long
3959 const timer = setTimeout ( ( ) => {
4060 log ( ) ;
4161 log ( chalk . red ( "Timeout exceeded." ) ) ;
4262 log ( ) ;
4363
44- reject ( new Error ( "Timeout exceeded" ) ) ;
64+ closeBrowser ( browser , new Error ( "Timeout exceeded" ) ) ;
4565 } , timeout || defaults . timeout ) ;
4666
47- log ( "Testing" , chalk . magenta ( fixturePath ) ) ;
48-
49- const browser = await puppeteer . launch ( ) ;
50- const page = await browser . newPage ( ) ;
51- const failures = [ ] ;
52-
5367 await page . exposeFunction ( "logAssertion" , async response => {
5468 // Don't log if the test passed or it's a todo test
5569 if ( ! response . result && ! response . todo ) {
@@ -124,11 +138,7 @@ const qunitChromeRunner = (
124138
125139 log ( chalk . blue ( `Took ${ response . runtime } ms to run ${ response . total } tests. ${ response . passed } passed, ${ response . failed } failed.` ) ) ;
126140
127- try {
128- await browser . close ( ) ;
129- } catch ( ex ) {
130- // Failed to close the browser, handle silently
131- }
141+ await closeBrowser ( browser ) ;
132142
133143 // Get rid of our timeout timer because we're done
134144 clearTimeout ( timer ) ;
@@ -153,7 +163,7 @@ const qunitChromeRunner = (
153163 log ( chalk . red ( "Unable to find the QUnit object." ) ) ;
154164 log ( ) ;
155165
156- reject ( new Error ( "Unable to find the QUnit object" ) ) ;
166+ await closeBrowser ( browser , new Error ( "Unable to find the QUnit object" ) ) ;
157167 }
158168
159169 await page . evaluate ( ( ) => {
@@ -167,7 +177,11 @@ const qunitChromeRunner = (
167177 try {
168178 await page . goto ( fixturePath ) ;
169179 } catch ( ex ) {
170- reject ( new Error ( "Failed to open the test file." ) ) ;
180+ log ( ) ;
181+ log ( chalk . red ( "Failed to open the test file." ) ) ;
182+ log ( ) ;
183+
184+ await closeBrowser ( browser , new Error ( "Failed to open the test file." ) ) ;
171185 }
172186 } ) ( ) ;
173187 } ) ;
0 commit comments