Unverified Commit e33b7dd2 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Stabilize back-forward-cache test cases (#78735)

This attempts to stabilize the back-forward-cache test assertions by
adding retry to the initial button incrementing as I have a theory this
was attempting to click before the event listeners were attached causing
the clicks to be missed which makes the successive test cases fail.

x-ref:
https://github.com/vercel/next.js/actions/runs/14766354734/job/41458564789#step:33:481
x-ref:
https://github.com/vercel/next.js/actions/runs/14766354734/job/41459734942#step:33:191
parent d6fd8d57
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('back/forward cache', () => {
const { next } = nextTestSetup({
......@@ -9,10 +10,17 @@ describe('back/forward cache', () => {
const browser = await next.browser('/page/1')
// Accumulate some state on page 1.
const incrementButton1 = await browser.elementById('increment-button-1')
await retry(async () => {
// we do this inside of retry in case button event handler
// isn't ready yet
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
expect(await counterDisplay1.text()).toBe('Count: 1')
})
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
await incrementButton1.click()
await incrementButton1.click()
expect(await counterDisplay1.text()).toBe('Count: 2')
// Navigate to page 2. Accumulate some state here, too.
......@@ -48,10 +56,18 @@ describe('back/forward cache', () => {
const browser = await next.browser('/page/1')
// Accumulate some state on page 1.
const incrementButton1 = await browser.elementById('increment-button-1')
// Accumulate some state on page 1.
await retry(async () => {
// we do this inside of retry in case button event handler
// isn't ready yet
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
expect(await counterDisplay1.text()).toBe('Count: 1')
})
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
await incrementButton1.click()
await incrementButton1.click()
expect(await counterDisplay1.text()).toBe('Count: 2')
// Navigate to page 2. Accumulate some state here, too.
......@@ -88,10 +104,17 @@ describe('back/forward cache', () => {
const browser = await next.browser('/page/1')
// Accumulate some state on page 1.
const incrementButton1 = await browser.elementById('increment-button-1')
await retry(async () => {
// we do this inside of retry in case button event handler
// isn't ready yet
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
expect(await counterDisplay1.text()).toBe('Count: 1')
})
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
await incrementButton1.click()
await incrementButton1.click()
expect(await counterDisplay1.text()).toBe('Count: 2')
// Navigate to page 2.
......@@ -103,11 +126,14 @@ describe('back/forward cache', () => {
'a[href="/page/1?param=true"]'
)
await linkToPage1WithSearchParam.click()
const counterDisplay1AfterNav =
await browser.elementById('counter-display-1')
const hasSearchParam = await browser.elementById('has-search-param-1')
expect(await counterDisplay1AfterNav.text()).toBe('Count: 2')
expect(await hasSearchParam.text()).toBe('Has search param: yes')
await retry(async () => {
const counterDisplay1AfterNav =
await browser.elementById('counter-display-1')
const hasSearchParam = await browser.elementById('has-search-param-1')
expect(await counterDisplay1AfterNav.text()).toBe('Count: 2')
expect(await hasSearchParam.text()).toBe('Has search param: yes')
})
})
it('bfcache only preserves up to N entries', async () => {
......@@ -115,15 +141,23 @@ describe('back/forward cache', () => {
const browser = await next.browser('/page/1')
// Accumulate some state on page 1.
const incrementButton1 = await browser.elementById('increment-button-1')
await retry(async () => {
// we do this inside of retry in case button event handler
// isn't ready yet
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
expect(await counterDisplay1.text()).toBe('Count: 1')
})
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
await incrementButton1.click()
await incrementButton1.click()
expect(await counterDisplay1.text()).toBe('Count: 2')
// Navigate to page 2. Accumulate some state here, too.
const linkToPage2 = await browser.elementByCss('a[href="/page/2"]')
await linkToPage2.click()
const incrementButton2 = await browser.elementById('increment-button-2')
const counterDisplay2 = await browser.elementById('counter-display-2')
await incrementButton2.click()
......@@ -153,11 +187,14 @@ describe('back/forward cache', () => {
expect(await counterDisplay2AfterNav.text()).toBe('Count: 9')
// Navigate back to page 1 to confirm its state is not preserved.
const linkToPage1 = await browser.elementByCss('a[href="/page/1"]')
await linkToPage1.click()
const counterDisplay1AfterNav =
await browser.elementById('counter-display-1')
expect(await counterDisplay1AfterNav.text()).toBe('Count: 0')
await retry(async () => {
const linkToPage1 = await browser.elementByCss('a[href="/page/1"]')
await linkToPage1.click()
const counterDisplay1AfterNav =
await browser.elementById('counter-display-1')
expect(await counterDisplay1AfterNav.text()).toBe('Count: 0')
})
})
it('navigate back and forth repeatedly between the same pages without evicting', async () => {
......@@ -165,10 +202,17 @@ describe('back/forward cache', () => {
const browser = await next.browser('/page/1')
// Accumulate some state on page 1.
const incrementButton1 = await browser.elementById('increment-button-1')
await retry(async () => {
// we do this inside of retry in case button event handler
// isn't ready yet
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
expect(await counterDisplay1.text()).toBe('Count: 1')
})
await browser.elementById('increment-button-1').click()
const counterDisplay1 = await browser.elementById('counter-display-1')
await incrementButton1.click()
await incrementButton1.click()
expect(await counterDisplay1.text()).toBe('Count: 2')
// Navigate to page 2. Accumulate some state here, too.
......
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