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 -->
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { check } from 'next-test-utils'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('basePath query/hash handling', () => {
|
|
const basePath = '/docs'
|
|
const { next } = nextTestSetup({
|
|
files: __dirname,
|
|
nextConfig: {
|
|
basePath,
|
|
onDemandEntries: {
|
|
// Make sure entries are not getting disposed.
|
|
maxInactiveAge: 1000 * 60 * 60,
|
|
},
|
|
},
|
|
})
|
|
|
|
it.each([
|
|
{ hash: '#hello?' },
|
|
{ hash: '#?' },
|
|
{ hash: '##' },
|
|
{ hash: '##?' },
|
|
{ hash: '##hello?' },
|
|
{ hash: '##hello' },
|
|
{ hash: '#hello?world' },
|
|
{ search: '?hello=world', hash: '#a', query: { hello: 'world' } },
|
|
{ search: '?hello', hash: '#a', query: { hello: '' } },
|
|
{ search: '?hello=', hash: '#a', query: { hello: '' } },
|
|
])(
|
|
'is correct during query updating $hash $search',
|
|
async ({ hash, search, query }) => {
|
|
const browser = await next.browser(
|
|
`${basePath}${search || ''}${hash || ''}`
|
|
)
|
|
|
|
await check(
|
|
() =>
|
|
browser.eval('window.next.router.isReady ? "ready" : "not ready"'),
|
|
'ready'
|
|
)
|
|
expect(await browser.eval('window.location.pathname')).toBe(basePath)
|
|
expect(await browser.eval('window.location.search')).toBe(search || '')
|
|
expect(await browser.eval('window.location.hash')).toBe(hash || '')
|
|
expect(await browser.eval('next.router.pathname')).toBe('/')
|
|
expect(
|
|
JSON.parse(await browser.eval('JSON.stringify(next.router.query)'))
|
|
).toEqual(query || {})
|
|
}
|
|
)
|
|
|
|
it('should work with hash links', async () => {
|
|
const browser = await next.browser(`${basePath}/hello`)
|
|
await browser.elementByCss('#hashlink').click()
|
|
const url = new URL(await browser.eval(() => window.location.href))
|
|
expect(url.pathname).toBe(`${basePath}/hello`)
|
|
expect(url.hash).toBe('#hashlink')
|
|
})
|
|
})
|