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 -->
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { nextTestSetup, type Playwright } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
|
|
describe('router autoscrolling on navigation with css modules', () => {
|
|
const { next } = nextTestSetup({
|
|
files: __dirname,
|
|
})
|
|
const getTopScroll = async (browser: Playwright) =>
|
|
await browser.eval('document.documentElement.scrollTop')
|
|
|
|
const getLeftScroll = async (browser: Playwright) =>
|
|
await browser.eval('document.documentElement.scrollLeft')
|
|
|
|
const waitForScrollToComplete = async (
|
|
browser: Playwright,
|
|
options: { x: number; y: number }
|
|
) => {
|
|
await retry(async function expectScrolledTo() {
|
|
const top = await getTopScroll(browser)
|
|
const left = await getLeftScroll(browser)
|
|
expect({ top, left }).toEqual({ top: options.y, left: options.x })
|
|
})
|
|
}
|
|
|
|
const scrollTo = async (
|
|
browser: Playwright,
|
|
options: { x: number; y: number }
|
|
) => {
|
|
await browser.eval(`window.scrollTo(${options.x}, ${options.y})`)
|
|
await waitForScrollToComplete(browser, options)
|
|
}
|
|
|
|
describe('vertical scroll when page imports css modules', () => {
|
|
it('should scroll to top of document when navigating between to pages without layout when', async () => {
|
|
const browser = await next.browser('/1')
|
|
await browser.waitForElementByCss('#lower')
|
|
|
|
await scrollTo(browser, { x: 0, y: 1000 })
|
|
expect(await getTopScroll(browser)).toBe(1000)
|
|
|
|
await browser.elementById('lower').click()
|
|
await waitForScrollToComplete(browser, { x: 0, y: 0 })
|
|
})
|
|
|
|
it('should scroll when clicking in JS', async () => {
|
|
const browser = await next.browser('/1')
|
|
await browser.waitForElementByCss('#lower')
|
|
|
|
await scrollTo(browser, { x: 0, y: 1000 })
|
|
expect(await getTopScroll(browser)).toBe(1000)
|
|
|
|
await browser.eval(() => document.getElementById('lower').click())
|
|
await waitForScrollToComplete(browser, { x: 0, y: 0 })
|
|
})
|
|
})
|
|
})
|