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

71 lines
2.3 KiB
TypeScript

import { join } from 'path'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('i18n-data-fetching-redirect', () => {
// TODO: investigate tests failures on deploy
if ((global as any).isNextDeploy) {
it('should skip temporarily', () => {})
return
}
const { next } = nextTestSetup({
files: {
pages: new FileRef(join(__dirname, 'app/pages')),
'next.config.js': new FileRef(join(__dirname, 'app/next.config.js')),
},
dependencies: {},
})
describe('Redirect to locale from context', () => {
test.each`
path | locale
${'gssp-redirect'} | ${'en'}
${'gssp-redirect'} | ${'sv'}
${'gsp-blocking-redirect'} | ${'en'}
${'gsp-blocking-redirect'} | ${'sv'}
${'gsp-fallback-redirect'} | ${'en'}
${'gsp-fallback-redirect'} | ${'sv'}
`('$path $locale', async ({ path, locale }) => {
const browser = await next.browser(`/${locale}/${path}/from-ctx`)
await check(
() => browser.eval('window.location.pathname'),
`/${locale}/home`
)
expect(await browser.elementByCss('#router-locale').text()).toBe(locale)
expect(await browser.elementByCss('#router-pathname').text()).toBe(
'/home'
)
expect(await browser.elementByCss('#router-as-path').text()).toBe('/home')
})
test.each`
path | locale
${'gssp-redirect'} | ${'en'}
${'gssp-redirect'} | ${'sv'}
${'gsp-blocking-redirect'} | ${'en'}
${'gsp-blocking-redirect'} | ${'sv'}
${'gsp-fallback-redirect'} | ${'en'}
${'gsp-fallback-redirect'} | ${'sv'}
`('next/link $path $locale', async ({ path, locale }) => {
const browser = await next.browser(`/${locale}`)
await browser.eval('window.beforeNav = 1')
await browser.elementByCss(`#to-${path}-from-ctx`).click()
await check(
() => browser.eval('window.location.pathname'),
`/${locale}/home`
)
expect(await browser.eval('window.beforeNav')).toBe(1)
expect(await browser.elementByCss('#router-locale').text()).toBe(locale)
expect(await browser.elementByCss('#router-pathname').text()).toBe(
'/home'
)
expect(await browser.elementByCss('#router-as-path').text()).toBe('/home')
})
})
})