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 -->
72 lines
1.6 KiB
TypeScript
72 lines
1.6 KiB
TypeScript
import type { Playwright } from 'e2e-utils'
|
|
|
|
export const getPathname = (url: string) => {
|
|
const urlObj = new URL(url)
|
|
return urlObj.pathname
|
|
}
|
|
|
|
export const browserConfigWithFixedTime = {
|
|
beforePageLoad: (page) => {
|
|
page.addInitScript(() => {
|
|
const startTime = new Date()
|
|
const fixedTime = new Date('2023-04-17T00:00:00Z')
|
|
|
|
// Override the Date constructor
|
|
// @ts-ignore
|
|
// eslint-disable-next-line no-native-reassign
|
|
Date = class extends Date {
|
|
constructor() {
|
|
super()
|
|
// @ts-ignore
|
|
return new startTime.constructor(fixedTime)
|
|
}
|
|
|
|
static now() {
|
|
return fixedTime.getTime()
|
|
}
|
|
}
|
|
})
|
|
},
|
|
}
|
|
|
|
export const fastForwardTo = (ms) => {
|
|
// Increment the fixed time by the specified duration
|
|
const currentTime = new Date()
|
|
currentTime.setTime(currentTime.getTime() + ms)
|
|
|
|
// Update the Date constructor to use the new fixed time
|
|
// @ts-ignore
|
|
// eslint-disable-next-line no-native-reassign
|
|
Date = class extends Date {
|
|
constructor() {
|
|
super()
|
|
// @ts-ignore
|
|
return new currentTime.constructor(currentTime)
|
|
}
|
|
|
|
static now() {
|
|
return currentTime.getTime()
|
|
}
|
|
}
|
|
}
|
|
|
|
export 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 = []
|
|
},
|
|
}
|
|
}
|