mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Enable skew protection for all start-mode tests when Turbopack is enabled (i.e. not dev). This works by setting `NEXT_DEPLOYMENT_ID` in the test infra - When running the tests, `packages/next/src/server/lib/router-utils/resolve-routes.ts` now validates that all static asset requests have the correct `?dpl=...` query param value, and returns a 404 if missing. - It can be disabled with `disableAutoSkewProtection: true` in the test options - There were various tests that were asserting URLs and were missing the optional `?dpl` at the end. - `next.getDeploymentIdQuery()` can be used to get the `?dpl=dpl_123912js` string (or an empty string) - `next.getAssetQuery()` currently behaves like `getDeploymentIdQuery`, but will switch to prefer the immutable static token in #88607
89 lines
2.0 KiB
TypeScript
89 lines
2.0 KiB
TypeScript
import { NextInstance, createNext } from 'e2e-utils'
|
|
import fs from 'fs-extra'
|
|
import {
|
|
findPort,
|
|
initNextServerScript,
|
|
killApp,
|
|
renderViaHTTP,
|
|
} from 'next-test-utils'
|
|
import { join } from 'path'
|
|
|
|
let MY_DEPLOYMENT_ID = 'test-deployment-id'
|
|
|
|
describe('standalone mode: runtimeServerDeploymentId', () => {
|
|
let next: NextInstance
|
|
let server
|
|
let appPort
|
|
let output = ''
|
|
|
|
beforeAll(async () => {
|
|
next = await createNext({
|
|
files: __dirname,
|
|
env: {
|
|
NEXT_DEPLOYMENT_ID: MY_DEPLOYMENT_ID,
|
|
},
|
|
skipStart: true,
|
|
disableAutoSkewProtection: true,
|
|
})
|
|
let { exitCode } = await next.build()
|
|
// eslint-disable-next-line jest/no-standalone-expect
|
|
expect(exitCode).toBe(0)
|
|
|
|
await fs.move(
|
|
join(next.testDir, '.next/standalone'),
|
|
join(next.testDir, 'standalone')
|
|
)
|
|
|
|
for (const file of await fs.readdir(next.testDir)) {
|
|
if (file !== 'standalone') {
|
|
await fs.remove(join(next.testDir, file))
|
|
console.log('removed', file)
|
|
}
|
|
}
|
|
|
|
const testServer = join(next.testDir, 'standalone/server.js')
|
|
appPort = await findPort()
|
|
server = await initNextServerScript(
|
|
testServer,
|
|
/- Local:/,
|
|
{
|
|
...process.env,
|
|
...next.env,
|
|
HOSTNAME: '::',
|
|
PORT: appPort,
|
|
NEXT_DEPLOYMENT_ID: MY_DEPLOYMENT_ID,
|
|
},
|
|
undefined,
|
|
{
|
|
cwd: next.testDir,
|
|
onStdout(msg) {
|
|
output += msg
|
|
},
|
|
onStderr(msg) {
|
|
output += msg
|
|
},
|
|
}
|
|
)
|
|
})
|
|
afterAll(async () => {
|
|
await next.destroy()
|
|
if (server) await killApp(server)
|
|
})
|
|
|
|
it.each([
|
|
'app-page',
|
|
'app-page-edge',
|
|
'app-route',
|
|
'app-route-edge',
|
|
'pages-page',
|
|
'pages-page-edge',
|
|
'api/pages-route',
|
|
'api/pages-route-edge',
|
|
])('it should load %s', async (name) => {
|
|
expect(output).toContain(`- Local:`)
|
|
|
|
let html = await renderViaHTTP(appPort, `/${name}`)
|
|
expect(html).toContain(`Hello from ${name}`)
|
|
})
|
|
})
|