Repository: nuxt/nuxt
File: test/e2e/hmr.test.ts (TypeScript)

Code before:
      // Track console logs
      const consoleLogs: Array<{ type: string, text: string }> = []
      page.on('console', (msg) => {
        consoleLogs.push({
          type: msg.type(),
          text: msg.text(),
        })
      })

      // Wait for HMR to process the new route
      await expect(() => consoleLogs.some(log => log.text.includes('hmr'))).toBeWithPolling(true)

      // Navigate to the new route
      await page.locator('a[href="/routes/non-existent"]').click()

      // Verify the new route content is rendered
      await expect(page.getByTestId('contents')).toHaveText('A new route!')

      // Filter expected warnings about route not existing before the update
      const filteredLogs = consoleLogs.filter(log => (log.type === 'warning' || log.type === 'error') && !log.text.includes('No match found for location with path "/routes/non-existent"'))

      // Verify no unexpected errors
      expect(filteredLogs).toStrictEqual([])
    })

    test.fail('#32177', async ({ page, goto }) => {
      await goto('/issues/32177')

      const pageContents = readFileSync(join(sourceDir, 'pages/issues/32177.vue'), 'utf8')
      writeFileSync(join(fixtureDir, 'pages/issues/32177.vue'), pageContents.replace('// #HMR_REPLACE', 'console.log("hmr")'))
      await new Promise(resolve => setTimeout(resolve, 100))
      await expect(page.getByTestId('contents')).toHaveText('Element 1, Element 2')
    })
  }
}


Review comment (suggestion):
```suggestion
    test('should allow hmr with useAsyncData (#32177)', async ({ page, goto }) => {
```

Code after:
      page.on('console', (msg) => {
        consoleLogs.push({
          type: msg.type(),
          text: msg.text(),
        })
      })

      // Wait for HMR to process the new route
      await expect(() => consoleLogs.some(log => log.text.includes('hmr'))).toBeWithPolling(true)

      // Navigate to the new route
      await page.locator('a[href="/routes/non-existent"]').click()

      // Verify the new route content is rendered
      await expect(page.getByTestId('contents')).toHaveText('A new route!')

      // Filter expected warnings about route not existing before the update
      const filteredLogs = consoleLogs.filter(log => (log.type === 'warning' || log.type === 'error') && !log.text.includes('No match found for location with path "/routes/non-existent"'))

      // Verify no unexpected errors
      expect(filteredLogs).toStrictEqual([])
    })

    test('should allow hmr with useAsyncData (#32177)', async ({ page, goto }) => {
      await goto('/issues/32177')

      const pageContents = readFileSync(join(sourceDir, 'app/pages/issues/32177.vue'), 'utf8')
      writeFileSync(join(fixtureDir, 'app/pages/issues/32177.vue'), pageContents.replace('// #HMR_REPLACE', 'console.log("hmr")'))
      await expect(page.getByTestId('contents')).toHaveText('Element 1, Element 2')
    })

    test('HMR with top-level await', async ({ page, goto }) => {
      const pageContents = readFileSync(join(sourceDir, 'app/pages/top-level-await.vue'), 'utf8')
      writeFileSync(join(fixtureDir, 'app/pages/top-level-await.vue'), pageContents)

      // Navigate and wait for full load
      await goto('/top-level-await')
      await expect(page.getByTestId('content')).toHaveText('loaded')

      // Trigger HMR by editing script
      writeFileSync(
        join(fixtureDir, 'app/pages/top-level-await.vue'),
        pageContents.replace('console.log(\'page loaded\')', '// console.log(\'page loaded\')'),
      )

      // Wait for HMR to process and check no errors
      await page.waitForTimeout(1000)
      expect(page).toHaveNoErrorsOrWarnings()
    })
  }
}