Unverified Commit 63dff61b authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] More `instant-navs-devtools` deflaking (#91345)

parent 5dd48e35
...@@ -3,7 +3,7 @@ import { retry, toggleDevToolsIndicatorPopover } from 'next-test-utils' ...@@ -3,7 +3,7 @@ import { retry, toggleDevToolsIndicatorPopover } from 'next-test-utils'
import { Playwright } from 'next-webdriver' import { Playwright } from 'next-webdriver'
describe('instant-nav-panel', () => { describe('instant-nav-panel', () => {
const { next } = nextTestSetup({ const { isNextDev, isTurbopack, next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
...@@ -14,12 +14,19 @@ describe('instant-nav-panel', () => { ...@@ -14,12 +14,19 @@ describe('instant-nav-panel', () => {
await new Promise((resolve) => await new Promise((resolve) =>
setTimeout( setTimeout(
resolve, resolve,
// MENU_DURATION_MS // MENU_DURATION_MS + some flakiness buffer
200 200 + 50
) )
) )
} }
async function waitForInstantModeCookie(browser: Playwright): Promise<void> {
await retry(async () => {
const cookie = await browser.eval(() => document.cookie)
expect(cookie).toMatch(/next-instant-navigation-testing=[^;]+/)
})
}
async function clearInstantModeCookie(browser: Playwright) { async function clearInstantModeCookie(browser: Playwright) {
await browser.eval(() => { await browser.eval(() => {
document.cookie = 'next-instant-navigation-testing=; path=/; max-age=0' document.cookie = 'next-instant-navigation-testing=; path=/; max-age=0'
...@@ -32,6 +39,7 @@ describe('instant-nav-panel', () => { ...@@ -32,6 +39,7 @@ describe('instant-nav-panel', () => {
async function clickStartClientNav(browser: Playwright) { async function clickStartClientNav(browser: Playwright) {
await browser.elementByCssInstant('[data-instant-nav-client]').click() await browser.elementByCssInstant('[data-instant-nav-client]').click()
await waitForInstantModeCookie(browser)
} }
async function getInstantNavPanelText(browser: Playwright): Promise<string> { async function getInstantNavPanelText(browser: Playwright): Promise<string> {
...@@ -84,6 +92,11 @@ describe('instant-nav-panel', () => { ...@@ -84,6 +92,11 @@ describe('instant-nav-panel', () => {
}) })
it('should show client nav state after clicking Start and navigating', async () => { it('should show client nav state after clicking Start and navigating', async () => {
const targetPage = '/target-page/my-post?search=foo'
if (isNextDev && !isTurbopack) {
// warmup target page compilation before clicking Start, to avoid extra flakiness.
void next.render(targetPage).catch(() => {})
}
const browser = await next.browser('/') const browser = await next.browser('/')
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
await browser.waitForElementByCss('[data-testid="home-title"]') await browser.waitForElementByCss('[data-testid="home-title"]')
...@@ -94,10 +107,7 @@ describe('instant-nav-panel', () => { ...@@ -94,10 +107,7 @@ describe('instant-nav-panel', () => {
await clickStartClientNav(browser) await clickStartClientNav(browser)
// Cookie should now be set // Cookie should now be set
await retry(async () => { await waitForInstantModeCookie(browser)
const cookie = await browser.eval(() => document.cookie)
expect(cookie).toContain('next-instant-navigation-testing=')
})
// Panel should show client-nav-waiting state // Panel should show client-nav-waiting state
await retry(async () => { await retry(async () => {
...@@ -107,9 +117,9 @@ describe('instant-nav-panel', () => { ...@@ -107,9 +117,9 @@ describe('instant-nav-panel', () => {
}) })
// Navigate to target page via SPA (use eval to bypass overlay pointer interception) // Navigate to target page via SPA (use eval to bypass overlay pointer interception)
await browser.eval(() => { await browser.eval((page) => {
document.querySelector<HTMLAnchorElement>('#link-to-target')!.click() document.querySelector<HTMLAnchorElement>(`[href="${page}"]`)!.click()
}) }, targetPage)
// Panel should transition to client-nav state // Panel should transition to client-nav state
await retry(async () => { await retry(async () => {
...@@ -124,6 +134,11 @@ describe('instant-nav-panel', () => { ...@@ -124,6 +134,11 @@ describe('instant-nav-panel', () => {
}) })
it('should show loading skeleton during SPA navigation after clicking Start', async () => { it('should show loading skeleton during SPA navigation after clicking Start', async () => {
const targetPage = '/target-page/my-post?search=foo'
if (isNextDev && !isTurbopack) {
// warmup target page compilation before clicking Start, to avoid extra flakiness.
void next.render(targetPage).catch(() => {})
}
const browser = await next.browser('/') const browser = await next.browser('/')
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
await browser.waitForElementByCss('[data-testid="home-title"]') await browser.waitForElementByCss('[data-testid="home-title"]')
...@@ -134,9 +149,9 @@ describe('instant-nav-panel', () => { ...@@ -134,9 +149,9 @@ describe('instant-nav-panel', () => {
await clickStartClientNav(browser) await clickStartClientNav(browser)
// Navigate to target page via SPA (use eval to bypass overlay pointer interception) // Navigate to target page via SPA (use eval to bypass overlay pointer interception)
await browser.eval(() => { await browser.eval((page) => {
document.querySelector<HTMLAnchorElement>('#link-to-target')!.click() document.querySelector<HTMLAnchorElement>(`[href="${page}"]`)!.click()
}) }, targetPage)
// The data fetching skeleton should be visible (dynamic content is locked). // The data fetching skeleton should be visible (dynamic content is locked).
// Use a longer timeout because dev mode needs to compile the target page. // Use a longer timeout because dev mode needs to compile the target page.
......
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