@@ -229,16 +229,17 @@ if (!isBuild) {
229229 } )
230230
231231 test ( 'not loaded dynamic import' , async ( ) => {
232- await page . goto ( viteTestUrl + '/counter/index.html' )
232+ await page . goto ( viteTestUrl + '/counter/index.html' , { waitUntil : 'load' } )
233233
234234 let btn = await page . $ ( 'button' )
235235 expect ( await btn . textContent ( ) ) . toBe ( 'Counter 0' )
236236 await btn . click ( )
237237 expect ( await btn . textContent ( ) ) . toBe ( 'Counter 1' )
238238
239239 // Modifying `index.ts` triggers a page reload, as expected
240+ const indexTsLoadPromise = page . waitForEvent ( 'load' )
240241 editFile ( 'counter/index.ts' , ( code ) => code )
241- await page . waitForNavigation ( )
242+ await indexTsLoadPromise
242243 btn = await page . $ ( 'button' )
243244 expect ( await btn . textContent ( ) ) . toBe ( 'Counter 0' )
244245
@@ -251,13 +252,12 @@ if (!isBuild) {
251252 // (Note that, a dynamic import that is never loaded and that does not
252253 // define `accept.module.hot.accept` may wrongfully trigger a full page
253254 // reload, see discussion at #7561.)
255+ const depTsLoadPromise = page . waitForEvent ( 'load' , { timeout : 1000 } )
254256 editFile ( 'counter/dep.ts' , ( code ) => code )
255- try {
256- await page . waitForNavigation ( { timeout : 1000 } )
257- } catch ( err ) {
258- const errMsg = 'page.waitForNavigation: Timeout 1000ms exceeded.'
259- expect ( err . message . slice ( 0 , errMsg . length ) ) . toBe ( errMsg )
260- }
257+ await expect ( depTsLoadPromise ) . rejects . toThrow (
258+ / p a g e \. w a i t F o r E v e n t : T i m e o u t \d + m s e x c e e d e d w h i l e w a i t i n g f o r e v e n t " l o a d " / ,
259+ )
260+
261261 btn = await page . $ ( 'button' )
262262 expect ( await btn . textContent ( ) ) . toBe ( 'Counter 1' )
263263 } )
@@ -653,21 +653,25 @@ if (!isBuild) {
653653 test ( 'css in html hmr' , async ( ) => {
654654 await page . goto ( viteTestUrl )
655655 expect ( await getBg ( '.import-image' ) ) . toMatch ( 'icon' )
656- await page . goto ( viteTestUrl + '/foo/' )
656+ await page . goto ( viteTestUrl + '/foo/' , { waitUntil : 'load' } )
657657 expect ( await getBg ( '.import-image' ) ) . toMatch ( 'icon' )
658+
659+ const loadPromise = page . waitForEvent ( 'load' )
658660 editFile ( 'index.html' , ( code ) => code . replace ( 'url("./icon.png")' , '' ) )
659- await page . waitForNavigation ( )
661+ await loadPromise
660662 expect ( await getBg ( '.import-image' ) ) . toMatch ( '' )
661663 } )
662664
663665 test ( 'HTML' , async ( ) => {
664666 await page . goto ( viteTestUrl + '/counter/index.html' )
665667 let btn = await page . $ ( 'button' )
666668 expect ( await btn . textContent ( ) ) . toBe ( 'Counter 0' )
669+
670+ const loadPromise = page . waitForEvent ( 'load' )
667671 editFile ( 'counter/index.html' , ( code ) =>
668672 code . replace ( 'Counter' , 'Compteur' ) ,
669673 )
670- await page . waitForNavigation ( )
674+ await loadPromise
671675 btn = await page . $ ( 'button' )
672676 expect ( await btn . textContent ( ) ) . toBe ( 'Compteur 0' )
673677 } )
@@ -701,18 +705,20 @@ if (!isBuild) {
701705 const unImportCode = `// ${ importCode } `
702706 const timeout = 2000
703707
704- await page . goto ( viteTestUrl + '/missing-import/index.html' )
708+ await page . goto ( viteTestUrl + '/missing-import/index.html' , {
709+ waitUntil : 'load' ,
710+ } )
705711
706712 await untilBrowserLogAfter ( async ( ) => {
707- const navigationPromise = page . waitForNavigation ( { timeout } )
713+ const loadPromise = page . waitForEvent ( 'load' , { timeout } )
708714 editFile ( file , ( code ) => code . replace ( importCode , unImportCode ) )
709- await navigationPromise
715+ await loadPromise
710716 } , 'missing test' )
711717
712718 await untilBrowserLogAfter ( async ( ) => {
713- const navigationPromise = page . waitForNavigation ( { timeout } )
719+ const loadPromise = page . waitForEvent ( 'load' , { timeout } )
714720 editFile ( file , ( code ) => code . replace ( unImportCode , importCode ) )
715- await navigationPromise
721+ await loadPromise
716722 } , / 5 0 0 / )
717723 } )
718724
0 commit comments