@@ -22,6 +22,9 @@ const sandboxArgs = process.getuid?.() === 0 ? ['--no-sandbox'] : [];
2222const EDITOR_URL = / \/ r e n d e r e r \/ i n d e x \. h t m l $ / ;
2323const PAGE_WINDOW_URL = / \/ r e n d e r e r \/ i n d e x \. h t m l # p a g e - w i n d o w $ / ;
2424
25+ /** A window opening or closing, and Playwright hearing of it: past expect.poll's default second on a busy machine. */
26+ const WINDOW_TIMEOUT = { timeout : 10_000 } ;
27+
2528/** Polls until `fn` returns a truthy value (usable outside tests, unlike expect.poll). */
2629async function waitFor < T > ( fn : ( ) => T | undefined , timeout = 30_000 ) : Promise < T > {
2730 const deadline = Date . now ( ) + timeout ;
@@ -163,7 +166,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
163166 const own = await pageWindow ( app ) ;
164167 await inSite ( 'window.marker = 43' ) ;
165168 await putBack ( own ) ;
166- await expect . poll ( openWindows ) . toBe ( 0 ) ;
169+ await expect . poll ( openWindows , WINDOW_TIMEOUT ) . toBe ( 0 ) ;
167170 await expect . poll ( async ( ) => ( await host ( ) ) ?. hash ) . toBe ( '' ) ;
168171 await expect . poll ( async ( ) => ( await host ( ) ) ?. view . width ) . toBeGreaterThan ( 0 ) ;
169172 expect ( await inSite ( 'window.marker' ) ) . toBe ( 43 ) ;
@@ -180,7 +183,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
180183 BrowserWindow . getAllWindows ( ) . find ( ( w ) => w . webContents . getURL ( ) . endsWith ( '#page-window' ) ) ! . setBounds ( bounds ) ;
181184 } , moved ) ;
182185 await app . evaluate ( ( { BrowserWindow } ) => BrowserWindow . getAllWindows ( ) . find ( ( w ) => w . webContents . getURL ( ) . endsWith ( '#page-window' ) ) ! . close ( ) ) ;
183- await expect . poll ( openWindows ) . toBe ( 0 ) ;
186+ await expect . poll ( openWindows , WINDOW_TIMEOUT ) . toBe ( 0 ) ;
184187 await expect . poll ( async ( ) => ( await host ( ) ) ?. hash ) . toBe ( '' ) ;
185188 await expect . poll ( async ( ) => ( await savedPlacement ( ) ) . bounds ) . toEqual ( moved ) ;
186189
@@ -197,7 +200,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
197200
198201 it ( "brings it back from the editor's title bar, and the View menu moves it either way" , async ( ) => {
199202 await win . getByRole ( 'button' , { name : 'Show website preview' } ) . click ( ) ;
200- await expect . poll ( openWindows ) . toBe ( 0 ) ;
203+ await expect . poll ( openWindows , WINDOW_TIMEOUT ) . toBe ( 0 ) ;
201204 await expect . poll ( async ( ) => ( await host ( ) ) ?. hash ) . toBe ( '' ) ;
202205
203206 const menu = ( action : 'click' | 'checked' ) =>
@@ -213,7 +216,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
213216 await pageWindow ( app ) ;
214217 await expect . poll ( ( ) => menu ( 'checked' ) ) . toBe ( true ) ;
215218 await menu ( 'click' ) ;
216- await expect . poll ( openWindows ) . toBe ( 0 ) ;
219+ await expect . poll ( openWindows , WINDOW_TIMEOUT ) . toBe ( 0 ) ;
217220 await expect . poll ( ( ) => menu ( 'checked' ) ) . toBe ( false ) ;
218221 await expect . poll ( ( ) => win . getByRole ( 'region' , { name : 'Website preview' } ) . count ( ) ) . toBe ( 1 ) ;
219222 await expect . poll ( async ( ) => ( await host ( ) ) ?. view . width ) . toBeGreaterThan ( 0 ) ;
@@ -229,13 +232,13 @@ describe.skipIf(!built)('The website in a window of its own', () => {
229232 const popup = BrowserWindow . getAllWindows ( ) . find ( ( w ) => w . webContents . getURL ( ) === url ) ;
230233 return popup ? ( popup . getParentWindow ( ) ?. webContents . getURL ( ) ?? null ) : undefined ;
231234 } , `${ site . url } /frames.html?popup` ) ;
232- await expect . poll ( popupParent ) . toMatch ( PAGE_WINDOW_URL ) ;
235+ await expect . poll ( popupParent , WINDOW_TIMEOUT ) . toMatch ( PAGE_WINDOW_URL ) ;
233236
234237 await putBack ( await pageWindow ( app ) ) ;
235- await expect . poll ( openWindows ) . toBe ( 0 ) ;
238+ await expect . poll ( openWindows , WINDOW_TIMEOUT ) . toBe ( 0 ) ;
236239 await expect . poll ( popupParent ) . toMatch ( EDITOR_URL ) ;
237240 await app . evaluate ( ( { BrowserWindow } , url ) => BrowserWindow . getAllWindows ( ) . find ( ( w ) => w . webContents . getURL ( ) === url ) ?. close ( ) , `${ site . url } /frames.html?popup` ) ;
238- await expect . poll ( popupParent ) . toBeUndefined ( ) ;
241+ await expect . poll ( popupParent , WINDOW_TIMEOUT ) . toBeUndefined ( ) ;
239242 } ) ;
240243
241244 it ( 'copes with being put back, or asked for its address bar, while its window still loads' , async ( ) => {
@@ -262,7 +265,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
262265 const own = await pageWindow ( app ) ;
263266 await expect . poll ( ( ) => own . getByTestId ( 'address-bar' ) . evaluate ( ( el ) => el === el . ownerDocument . activeElement ) ) . toBe ( true ) ;
264267 await putBack ( own ) ;
265- await expect . poll ( openWindows ) . toBe ( 0 ) ;
268+ await expect . poll ( openWindows , WINDOW_TIMEOUT ) . toBe ( 0 ) ;
266269 } ) ;
267270
268271 it ( 'opens in its own window again after a restart, if it was there when the app quit' , async ( ) => {
0 commit comments