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 -->
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
import path from 'path'
|
|
import http from 'http'
|
|
import fs from 'fs'
|
|
import cheerio from 'cheerio'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('Export Dynamic Pages', () => {
|
|
const { next } = nextTestSetup({
|
|
files: __dirname,
|
|
skipStart: true,
|
|
})
|
|
|
|
let server: http.Server
|
|
let port: number
|
|
beforeAll(async () => {
|
|
await next.build()
|
|
|
|
const outDir = path.join(next.testDir, 'out')
|
|
server = http.createServer((req, res) => {
|
|
let urlPath = (req.url || '/').split('?')[0]
|
|
try {
|
|
urlPath = decodeURIComponent(urlPath)
|
|
} catch {}
|
|
let filePath = path.join(outDir, urlPath)
|
|
|
|
if (!path.extname(filePath)) {
|
|
filePath += '.html'
|
|
}
|
|
|
|
fs.readFile(filePath, (err, data) => {
|
|
if (err) {
|
|
res.writeHead(404)
|
|
res.end('Not Found')
|
|
return
|
|
}
|
|
const ext = path.extname(filePath)
|
|
const contentType =
|
|
{
|
|
'.html': 'text/html',
|
|
'.js': 'application/javascript',
|
|
'.css': 'text/css',
|
|
'.json': 'application/json',
|
|
}[ext] || 'application/octet-stream'
|
|
res.writeHead(200, { 'Content-Type': contentType })
|
|
res.end(data)
|
|
})
|
|
})
|
|
|
|
await new Promise<void>((resolve) => {
|
|
server.listen(0, () => resolve())
|
|
})
|
|
port = (server.address() as import('net').AddressInfo).port
|
|
})
|
|
|
|
afterAll(async () => {
|
|
if (server) {
|
|
await new Promise<void>((resolve) => server.close(() => resolve()))
|
|
}
|
|
})
|
|
|
|
it('should of exported with correct asPath', async () => {
|
|
const html = await next.readFile('out/regression/jeff-is-cool.html')
|
|
const $ = cheerio.load(html)
|
|
expect($('#asPath').text()).toBe('/regression/jeff-is-cool')
|
|
})
|
|
|
|
it('should hydrate with correct asPath', async () => {
|
|
expect.assertions(1)
|
|
const browser = await next.browser('/regression/jeff-is-cool', {
|
|
baseUrl: port,
|
|
})
|
|
try {
|
|
expect(await browser.eval(`window.__AS_PATHS`)).toEqual([
|
|
'/regression/jeff-is-cool',
|
|
])
|
|
} finally {
|
|
await browser.close()
|
|
}
|
|
})
|
|
})
|