Files
Tim NeutkensandGitHub e860cec656 test: migrate webdriver callers to next.browser (#93941)
### What?

Migrate remaining direct `next-webdriver` test callers that have a
`NextInstance` to `next.browser()`, and expose the shared `Playwright`
browser type from `e2e-utils`.

### Why?

`NextInstance.browser` should be the supported browser-opening interface
for test fixtures, with `next-webdriver` kept as the private
implementation detail.

### How?

Updated affected development, e2e, and production tests to call
`next.browser()` directly, passing `baseUrl` where tests intentionally
target a manually spawned or proxied server. Shared helpers now receive
browser callbacks from the test context, and browser types import
`Playwright` from `e2e-utils` instead of deriving from `next.browser` or
importing from private paths.

<!-- NEXT_JS_LLM_PR -->
2026-05-22 14:01:58 +02:00

86 lines
2.5 KiB
TypeScript

import { join } from 'path'
import { FileRef, nextTestSetup, type Playwright } from 'e2e-utils'
import { check, waitFor } from 'next-test-utils'
import type { HistoryState } from 'next/dist/shared/lib/router/router'
const emitPopsStateEvent = (browser: Playwright, state: HistoryState) =>
browser.eval(
`window.dispatchEvent(new PopStateEvent("popstate", { state: ${JSON.stringify(
state
)} }))`
)
describe('i18n: Event with stale state - static route previously was dynamic', () => {
const { next } = nextTestSetup({
files: {
pages: new FileRef(join(__dirname, 'app/pages')),
'next.config.js': new FileRef(join(__dirname, 'app/next.config.js')),
},
dependencies: {},
})
test('Ignore event without query param', async () => {
const browser = await next.browser('/sv/static')
const state: HistoryState = {
url: '/[dynamic]?',
as: '/static',
options: { locale: 'sv' },
__N: true,
key: '',
}
expect(await browser.elementByCss('#page-type').text()).toBe('static')
// 1st event is ignored
await emitPopsStateEvent(browser, state)
await waitFor(1000)
expect(await browser.elementByCss('#page-type').text()).toBe('static')
// 2nd event isn't ignored
await emitPopsStateEvent(browser, state)
await check(() => browser.elementByCss('#page-type').text(), 'dynamic')
})
test('Ignore event with query param', async () => {
const browser = await next.browser('/sv/static?param=1')
const state: HistoryState = {
url: '/[dynamic]?param=1',
as: '/static?param=1',
options: { locale: 'sv' },
__N: true,
key: '',
}
expect(await browser.elementByCss('#page-type').text()).toBe('static')
// 1st event is ignored
await emitPopsStateEvent(browser, state)
await waitFor(1000)
expect(await browser.elementByCss('#page-type').text()).toBe('static')
// 2nd event isn't ignored
await emitPopsStateEvent(browser, state)
await check(() => browser.elementByCss('#page-type').text(), 'dynamic')
})
test("Don't ignore event with different locale", async () => {
const browser = await next.browser('/sv/static?param=1')
const state: HistoryState = {
url: '/[dynamic]?param=1',
as: '/static?param=1',
options: { locale: 'en' },
__N: true,
key: '',
}
expect(await browser.elementByCss('#page-type').text()).toBe('static')
await emitPopsStateEvent(browser, state)
await check(() => browser.elementByCss('#page-type').text(), 'dynamic')
})
})