@@ -9,7 +9,7 @@ describe('chunk-load-failure', () => {
99 files : __dirname ,
1010 } )
1111
12- it ( 'should report async chunk load failures' , async ( ) => {
12+ async function getNextDynamicChunk ( ) {
1313 const chunksPath = path . join ( next . testDir , '.next/static/' )
1414 const browserChunks = await recursiveReadDir ( chunksPath , {
1515 pathnameFilter : ( f ) => / \. j s $ / . test ( f ) ,
@@ -20,7 +20,12 @@ describe('chunk-load-failure', () => {
2020 . includes ( 'this is a lazy loaded async component' )
2121 )
2222 expect ( nextDynamicChunks ) . toHaveLength ( 1 )
23- let nextDynamicChunk = nextDynamicChunks [ 0 ]
23+
24+ return nextDynamicChunks [ 0 ]
25+ }
26+
27+ it ( 'should report async chunk load failures' , async ( ) => {
28+ let nextDynamicChunk = await getNextDynamicChunk ( )
2429
2530 let pageError : Error | undefined
2631 const browser = await next . browser ( '/dynamic' , {
@@ -52,4 +57,51 @@ describe('chunk-load-failure', () => {
5257 expect ( pageError . message ) . toContain ( '/_next/static/' + nextDynamicChunk )
5358 }
5459 } )
60+
61+ it . each ( [ 'chrome' , 'firefox' ] ) (
62+ 'should report aborted chunks when navigating away with %s' ,
63+ async ( browserName ) => {
64+ let nextDynamicChunk = await getNextDynamicChunk ( )
65+
66+ let resolve
67+ let oldBrowserName = process . env . BROWSER_NAME
68+ process . env . BROWSER_NAME = browserName
69+ try {
70+ const browser = await next . browser ( '/dynamic' , {
71+ beforePageLoad ( page ) {
72+ page . route ( '**/' + nextDynamicChunk , async ( route ) => {
73+ await new Promise ( ( r ) => {
74+ resolve = r
75+ } )
76+ } )
77+ } ,
78+ } )
79+
80+ await browser . get ( next . url + '/other' )
81+
82+ let body = await browser . elementByCss ( 'body' )
83+ expect ( await body . text ( ) ) . toMatch ( 'this is other' )
84+
85+ const browserLogs = ( await browser . log ( ) ) . filter (
86+ ( m ) => m . source === 'warning' || m . source === 'error'
87+ )
88+ if ( browserName === 'firefox' ) {
89+ expect ( browserLogs ) . toContainEqual (
90+ expect . objectContaining ( {
91+ message : expect . stringContaining (
92+ 'Loading failed for the <script> with source'
93+ ) ,
94+ } )
95+ )
96+ } else {
97+ // Chrome doesn't show any errors or warnings here
98+ expect ( browserLogs ) . toBeEmpty ( )
99+ }
100+ } finally {
101+ process . env . BROWSER_NAME = oldBrowserName
102+ // prevent hanging
103+ resolve ?.( )
104+ }
105+ }
106+ )
55107} )
0 commit comments