mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +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 -->
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
import { check } from 'next-test-utils'
|
|
import { join } from 'path'
|
|
|
|
describe('nonce head manager', () => {
|
|
const { next } = nextTestSetup({
|
|
files: {
|
|
pages: new FileRef(join(__dirname, 'app/pages')),
|
|
public: new FileRef(join(__dirname, 'app/public')),
|
|
},
|
|
})
|
|
|
|
async function runTests(url) {
|
|
const browser = await next.browser(url)
|
|
await check(
|
|
async () =>
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
'["src-1.js"]'
|
|
)
|
|
|
|
await browser.elementByCss('#force-rerender').click()
|
|
await check(
|
|
async () =>
|
|
await browser.eval(`document.getElementById('h1').textContent`),
|
|
'Count 1'
|
|
)
|
|
await check(
|
|
async () =>
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
'["src-1.js"]'
|
|
)
|
|
|
|
await browser.elementByCss('#change-script').click()
|
|
await check(
|
|
async () =>
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
'["src-1.js","src-2.js"]'
|
|
)
|
|
|
|
await browser.elementByCss('#change-script').click()
|
|
await check(
|
|
async () =>
|
|
await browser.eval(`JSON.stringify(window.scriptExecutionIds)`),
|
|
'["src-1.js","src-2.js","src-1.js"]'
|
|
)
|
|
}
|
|
|
|
it('should not re-execute the script when re-rendering', async () => {
|
|
await runTests('/')
|
|
})
|
|
|
|
it('should not re-execute the script when re-rendering with CSP header', async () => {
|
|
await runTests('/csp')
|
|
})
|
|
})
|