mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### 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 -->
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { nextTestSetup, type Playwright } from 'e2e-utils'
|
|
|
|
const getPathname = (url: string) => {
|
|
const urlObj = new URL(url)
|
|
return urlObj.pathname
|
|
}
|
|
|
|
const createRequestsListener = async (browser: Playwright) => {
|
|
// wait for network idle
|
|
await browser.waitForIdleNetwork()
|
|
|
|
let requests = []
|
|
|
|
browser.on('request', (req) => {
|
|
requests.push([req.url(), !!req.headers()['next-router-prefetch']])
|
|
})
|
|
|
|
await browser.refresh()
|
|
|
|
return {
|
|
getRequests: () => requests,
|
|
clearRequests: () => {
|
|
requests = []
|
|
},
|
|
}
|
|
}
|
|
|
|
describe('app-prefetch-false', () => {
|
|
const { next, isNextDev } = nextTestSetup({
|
|
files: __dirname,
|
|
})
|
|
|
|
if (isNextDev) {
|
|
it.skip('should skip test in development mode', () => {})
|
|
} else {
|
|
it('should avoid double-fetching when optimistic navigation fails', async () => {
|
|
const browser = await next.browser('/foo')
|
|
const { getRequests } = await createRequestsListener(browser)
|
|
|
|
await browser.elementByCss('[href="/foo"]').click()
|
|
await browser.elementByCss('[href="/foo/bar"]').click()
|
|
console.log('getRequests()', getRequests())
|
|
expect(
|
|
getRequests().filter(([req]) => getPathname(req) === '/foo/bar').length
|
|
).toBe(1)
|
|
})
|
|
}
|
|
})
|