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
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import { FileRef, 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 ESM app dir', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: {
|
|
app: new FileRef(path.join(__dirname, 'app')),
|
|
pages: new FileRef(path.join(__dirname, 'pages')),
|
|
public: new FileRef(path.join(__dirname, 'public')),
|
|
'next.config.js': 'export default {"output": "standalone"}',
|
|
},
|
|
packageJson: {
|
|
type: 'module',
|
|
},
|
|
skipStart: true,
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
await next.start()
|
|
})
|
|
|
|
it('should work correctly with output standalone', async () => {
|
|
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
|
|
await fs.mkdirp(tmpFolder)
|
|
await fs.writeFile(
|
|
path.join(tmpFolder, 'package.json'),
|
|
'{"type": "module"}'
|
|
)
|
|
const distFolder = path.join(tmpFolder, 'test')
|
|
await fs.move(path.join(next.testDir, '.next/standalone'), distFolder)
|
|
let server: any
|
|
try {
|
|
const testServer = path.join(distFolder, 'server.js')
|
|
const appPort = await findPort()
|
|
server = await initNextServerScript(
|
|
testServer,
|
|
/- Local:/,
|
|
{
|
|
...process.env,
|
|
...next.env,
|
|
PORT: appPort.toString(),
|
|
},
|
|
undefined,
|
|
{
|
|
cwd: distFolder,
|
|
}
|
|
)
|
|
for (const testPath of ['/app', '/pages', '/opengraph-image']) {
|
|
const res = await fetchViaHTTP(appPort, testPath)
|
|
expect(res.status).toBe(200)
|
|
}
|
|
} finally {
|
|
if (server) await killApp(server)
|
|
await fs.remove(tmpFolder)
|
|
}
|
|
})
|
|
})
|
|
}
|