Unverified Commit 649d3026 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Unflake router events deploy test (#91589)

[Flakiness
metrics](https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest%20%40git.repository.id%3A%22github.com%2Fvercel%2Fnext.js%22%20%40test.status%3A%22fail%22%20%40test.name%3A%22basePath%20should%20use%20urls%20with%20basepath%20in%20router%20events%20for%20hash%20changes%22&agg_m=count&agg_m_source=base&agg_t=count&currentTab=overview&eventStack=&fromUser=false&index=citest&start=1773244604685&end=1773849404685&paused=false)

After upgrading Playwright in #91250 (which brought some performance
improvements), some tests are now exposed to be missing retries around
assertions. `test/e2e/basepath/router-events.test.ts` is one of those
tests, and this PR adds a `retry` around the event log assertion. We're
also replacing the deprecated `check` utility with `retry` when waiting
for the router to be ready.
parent bcd9c19a
import assert from 'assert' import assert from 'assert'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { check, retry } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('basePath', () => { describe('basePath', () => {
const basePath = '/docs' const basePath = '/docs'
...@@ -20,9 +20,8 @@ describe('basePath', () => { ...@@ -20,9 +20,8 @@ describe('basePath', () => {
it('should use urls with basepath in router events', async () => { it('should use urls with basepath in router events', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`) const browser = await webdriver(next.url, `${basePath}/hello`)
try { try {
await check( await retry(() =>
() => browser.eval('window.next.router.isReady ? "ready" : "no"'), expect(browser.eval('window.next.router.isReady')).resolves.toBe(true)
'ready'
) )
await browser.eval('window._clearEventLog()') await browser.eval('window._clearEventLog()')
await browser await browser
...@@ -46,22 +45,28 @@ describe('basePath', () => { ...@@ -46,22 +45,28 @@ describe('basePath', () => {
it('should use urls with basepath in router events for hash changes', async () => { it('should use urls with basepath in router events for hash changes', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`) const browser = await webdriver(next.url, `${basePath}/hello`)
try { try {
await check( await retry(() =>
() => browser.eval('window.next.router.isReady ? "ready" : "no"'), expect(browser.eval('window.next.router.isReady')).resolves.toBe(true)
'ready'
) )
await browser.eval('window._clearEventLog()') await browser.eval('window._clearEventLog()')
await browser.elementByCss('#hash-change').click() await browser.elementByCss('#hash-change').click()
const eventLog = await browser.eval('window._getEventLog()') await retry(async () => {
expect(eventLog).toEqual([ const eventLog = await browser.eval('window._getEventLog()')
['hashChangeStart', `${basePath}/hello#some-hash`, { shallow: false }],
[ expect(eventLog).toEqual([
'hashChangeComplete', [
`${basePath}/hello#some-hash`, 'hashChangeStart',
{ shallow: false }, `${basePath}/hello#some-hash`,
], { shallow: false },
]) ],
[
'hashChangeComplete',
`${basePath}/hello#some-hash`,
{ shallow: false },
],
])
})
} finally { } finally {
await browser.close() await browser.close()
} }
...@@ -70,9 +75,8 @@ describe('basePath', () => { ...@@ -70,9 +75,8 @@ describe('basePath', () => {
it('should use urls with basepath in router events for cancelled routes', async () => { it('should use urls with basepath in router events for cancelled routes', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`) const browser = await webdriver(next.url, `${basePath}/hello`)
try { try {
await check( await retry(() =>
() => browser.eval('window.next.router.isReady ? "ready" : "no"'), expect(browser.eval('window.next.router.isReady')).resolves.toBe(true)
'ready'
) )
await browser.eval('window._clearEventLog()') await browser.eval('window._clearEventLog()')
...@@ -105,9 +109,8 @@ describe('basePath', () => { ...@@ -105,9 +109,8 @@ describe('basePath', () => {
it('should use urls with basepath in router events for failed route change', async () => { it('should use urls with basepath in router events for failed route change', async () => {
const browser = await webdriver(next.url, `${basePath}/hello`) const browser = await webdriver(next.url, `${basePath}/hello`)
try { try {
await check( await retry(() =>
() => browser.eval('window.next.router.isReady ? "ready" : "no"'), expect(browser.eval('window.next.router.isReady')).resolves.toBe(true)
'ready'
) )
await browser.eval('window._clearEventLog()') await browser.eval('window._clearEventLog()')
await browser.elementByCss('#error-route').click() await browser.elementByCss('#error-route').click()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment