@@ -90,3 +90,52 @@ test.runIf(
9090 )
9191 expect ( stderr ) . toMatch ( / C a n n o t c o n n e c t t o t h e i f r a m e / )
9292} )
93+
94+ test . runIf ( provider . name === 'playwright' && instances . some ( ( i ) => i . browser === 'firefox' ) ) (
95+ 'vitest bails out when the iframe navigates away after the test dispatched pagehide' ,
96+ async ( ) => {
97+ const { stderr } = await runInlineBrowserTests (
98+ {
99+ 'navigate.test.ts' : `
100+ import { test } from 'vitest'
101+
102+ test('navigates away', async () => {
103+ window.dispatchEvent(new Event('pagehide'))
104+ location.href = 'http://127.0.0.1:1/'
105+ await new Promise(() => {})
106+ })
107+ ` ,
108+ } ,
109+ {
110+ browser : { instances : instances . filter ( ( instance ) => instance . browser === 'firefox' ) } ,
111+ } ,
112+ { fails : true } ,
113+ )
114+ expect ( stderr ) . toMatch ( / C a n n o t c o n n e c t t o t h e i f r a m e / )
115+ } ,
116+ )
117+
118+ test ( 'pagehide dispatched by the test does not fail the running file' , async ( ) => {
119+ const { stderr, testTree } = await runInlineBrowserTests (
120+ {
121+ 'pagehide.test.ts' : `
122+ import { test } from 'vitest'
123+
124+ test('runs page lifecycle code', async () => {
125+ window.dispatchEvent(new Event('pagehide'))
126+ await new Promise((resolve) => setTimeout(resolve, 6_000))
127+ })
128+ ` ,
129+ } ,
130+ { browser : { instances : [ instances [ 0 ] ] } } ,
131+ )
132+
133+ expect ( stderr ) . toBe ( '' )
134+ expect ( testTree ( ) ) . toMatchInlineSnapshot ( `
135+ {
136+ "pagehide.test.ts": {
137+ "runs page lifecycle code": "passed",
138+ },
139+ }
140+ ` )
141+ } )
0 commit comments