This repository was archived by the owner on Oct 1, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -148,12 +148,20 @@ const preprocessor = (options = {}) => {
148148 // we overwrite the latest bundle, so that a new call to this function
149149 // returns a promise that resolves when the bundling is finished
150150 latestBundle = createDeferred ( )
151- bundles [ filePath ] = latestBundle . promise . tap ( ( ) => {
151+ bundles [ filePath ] = latestBundle . promise
152+
153+ bundles [ filePath ] . tap ( ( ) => {
152154 debug ( '- compile finished for' , filePath )
153155 // when the bundling is finished, emit 'rerun' to let Cypress
154156 // know to rerun the spec
155157 file . emit ( 'rerun' )
156158 } )
159+ // we suppress unhandled rejections so they don't bubble up to the
160+ // unhandledRejection handler and crash the process. Cypress will
161+ // eventually take care of the rejection when the file is requested.
162+ // note that this does not work if attached to latestBundle.promise
163+ // for some reason. it only works when attached after .tap ¯\_(ツ)_/¯
164+ . suppressUnhandledRejections ( )
157165 }
158166
159167 // when we should watch, we hook into the 'compile' hook so we know when
Original file line number Diff line number Diff line change @@ -32,4 +32,27 @@ describe('webpack preprocessor - e2e', () => {
3232 snapshot ( fs . readFileSync ( outputPath ) . toString ( ) )
3333 } )
3434 } )
35+
36+ it ( 'allows attaching catch later on syntax error without triggering unhandled rejection' , ( done ) => {
37+ process . on ( 'unhandledRejection' , ( err ) => {
38+ // eslint-disable-next-line no-console
39+ console . error ( 'Unhandled Rejection:' , err . stack )
40+ done ( 'Should not have trigger unhandled rejection' )
41+ } )
42+
43+ file . shouldWatch = true
44+
45+ preprocessor ( ) ( file ) . then ( ( ) => {
46+ fs . outputFileSync ( filePath , '{' )
47+
48+ setTimeout ( ( ) => {
49+ preprocessor ( ) ( file )
50+ . catch ( ( err ) => {
51+ expect ( err . stack ) . to . include ( 'Unexpected token' )
52+ file . emit ( 'close' )
53+ done ( )
54+ } )
55+ } , 1000 )
56+ } )
57+ } )
3558} )
You can’t perform that action at this time.
0 commit comments