@@ -58,50 +58,49 @@ describe('chunk-load-failure', () => {
5858 }
5959 } )
6060
61- it . each ( [ 'chrome' , 'firefox' ] ) (
62- 'should report aborted chunks when navigating away with %s' ,
63- async ( browserName ) => {
64- let nextDynamicChunk = await getNextDynamicChunk ( )
61+ it ( 'should report aborted chunks when navigating away' , async ( ) => {
62+ let nextDynamicChunk = await getNextDynamicChunk ( )
6563
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- } )
64+ let resolve
65+ try {
66+ const browser = await next . browser ( '/dynamic' , {
67+ beforePageLoad ( page ) {
68+ page . route ( '**/' + nextDynamicChunk , async ( route ) => {
69+ // deterministically ensure that the async chunk is still loading during the navigation
70+ await new Promise ( ( r ) => {
71+ resolve = r
7672 } )
77- } ,
78- } )
73+ } )
74+ page . on ( 'pageerror' , ( error : Error ) => {
75+ console . log ( 'pageerror' , error )
76+ } )
77+ } ,
78+ } )
79+
80+ await browser . get ( next . url + '/other' )
7981
80- await browser . get ( next . url + '/other' )
82+ let body = await browser . elementByCss ( 'body' )
83+ expect ( await body . text ( ) ) . toMatch ( 'this is other' )
8184
82- let body = await browser . elementByCss ( 'body' )
83- expect ( await body . text ( ) ) . toMatch ( 'this is other' )
85+ const browserLogs = ( await browser . log ( ) ) . filter (
86+ ( m ) => m . source === 'warning' || m . source === 'error'
87+ )
8488
85- const browserLogs = ( await browser . log ( ) ) . filter (
86- ( m ) => m . source === 'warning' || m . source === 'error'
89+ if ( process . env . BROWSER_NAME === 'firefox' ) {
90+ expect ( browserLogs ) . toContainEqual (
91+ expect . objectContaining ( {
92+ message : expect . stringContaining (
93+ 'Loading failed for the <script> with source'
94+ ) ,
95+ } )
8796 )
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 ?.( )
97+ } else {
98+ // Chrome and Safari doesn't show any errors or warnings here
99+ expect ( browserLogs ) . toBeEmpty ( )
104100 }
101+ } finally {
102+ // prevent hanging
103+ resolve ?.( )
105104 }
106- )
105+ } )
107106} )
0 commit comments