mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +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
90 lines
2.0 KiB
TypeScript
90 lines
2.0 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import fs from 'fs-extra'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
import {
|
|
findPort,
|
|
initNextServerScript,
|
|
killApp,
|
|
fetchViaHTTP,
|
|
} from 'next-test-utils'
|
|
|
|
if (!(globalThis as any).isNextStart) {
|
|
it('should skip for non-next start', () => {})
|
|
} else {
|
|
describe('output: standalone with getStaticProps', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipStart: true,
|
|
dependencies: {
|
|
swr: 'latest',
|
|
nanoid: '4.0.1',
|
|
},
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
await next.patchFile(
|
|
'next.config.js',
|
|
(await next.readFile('next.config.js')).replace('// output', 'output')
|
|
)
|
|
|
|
await next.patchFile(
|
|
'pages/gsp.js',
|
|
`
|
|
import useSWR from 'swr'
|
|
|
|
console.log(useSWR)
|
|
|
|
export default function Home() {
|
|
return <h1>Hello</h1>
|
|
}
|
|
|
|
export async function getStaticProps() {
|
|
return {
|
|
props: {
|
|
foo: "bar",
|
|
},
|
|
};
|
|
}
|
|
`
|
|
)
|
|
|
|
await next.start()
|
|
})
|
|
|
|
it('should work correctly with output standalone', async () => {
|
|
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
|
|
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
|
|
let server: any
|
|
|
|
try {
|
|
const testServer = path.join(tmpFolder, 'server.js')
|
|
const appPort = await findPort()
|
|
server = await initNextServerScript(
|
|
testServer,
|
|
/- Local:/,
|
|
{
|
|
...process.env,
|
|
...next.env,
|
|
PORT: appPort.toString(),
|
|
},
|
|
undefined,
|
|
{
|
|
cwd: tmpFolder,
|
|
}
|
|
)
|
|
|
|
const res = await fetchViaHTTP(appPort, '/gsp')
|
|
expect(res.status).toBe(200)
|
|
} finally {
|
|
if (server) await killApp(server)
|
|
await fs.remove(tmpFolder)
|
|
}
|
|
})
|
|
})
|
|
}
|