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
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('invalid-static-asset-404-app-base-path', () => {
|
|
const { next } = nextTestSetup({
|
|
files: __dirname,
|
|
nextConfig: {
|
|
basePath: '/base',
|
|
},
|
|
})
|
|
|
|
it('should return correct output with status 200 on valid asset path', async () => {
|
|
const buildManifestPath = `/base/_next/static/${next.buildId}/_buildManifest.js${next.getDeploymentIdQuery()}`
|
|
|
|
const res = await next.fetch(buildManifestPath)
|
|
expect(res.status).toBe(200)
|
|
const text = await res.text()
|
|
expect(text).toContain('__BUILD_MANIFEST')
|
|
})
|
|
|
|
it('should return custom 404 page when fetching invalid non-asset path', async () => {
|
|
const res = await next.fetch('/base/invalid-path')
|
|
expect(res.status).toBe(404)
|
|
const text = await res.text()
|
|
expect(text).toContain('Custom Not Found')
|
|
})
|
|
|
|
it('should return 404 with plain text when fetching invalid asset path', async () => {
|
|
const res = await next.fetch('/base/_next/static/invalid-path')
|
|
expect(res.status).toBe(404)
|
|
const text = await res.text()
|
|
expect(text).toBe('Not Found')
|
|
})
|
|
})
|