mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## What? Converts existing `createNext()` usage into `nextTestSetup()`. `createNext()` was the setup step we had before `nextTestSetup()` was added. This PR focused on the simple conversion cases. There will be a follow-up to complete the last few. --------- Co-authored-by: Cursor <[email protected]>
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
import { join } from 'path'
|
|
import { fetchViaHTTP, waitFor } from 'next-test-utils'
|
|
|
|
describe('app-dir-prevent-304-caching', () => {
|
|
const { next } = nextTestSetup({
|
|
files: {
|
|
'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
|
|
app: new FileRef(join(__dirname, 'app')),
|
|
},
|
|
})
|
|
|
|
// https://github.com/vercel/next.js/issues/56580
|
|
it('should not cache 304 status', async () => {
|
|
// Ensure the first request hits a stale page triggering background revalidation.
|
|
await next.waitForMinPrerenderAge(1000 + 50)
|
|
const rStale = await fetchViaHTTP(next.url, '/')
|
|
expect(rStale.status).toBe(200)
|
|
|
|
await waitFor(500)
|
|
|
|
// Cache HIT but still 200
|
|
const rHit = await fetchViaHTTP(
|
|
next.url,
|
|
'/',
|
|
{},
|
|
{
|
|
headers: {
|
|
'If-None-Match': rStale.headers.get('etag'),
|
|
},
|
|
}
|
|
)
|
|
expect(rHit.status).toBe(200)
|
|
await waitFor(500)
|
|
|
|
// Here happens the race condition
|
|
const r304 = await fetchViaHTTP(
|
|
next.url,
|
|
'/',
|
|
{},
|
|
{
|
|
headers: {
|
|
'If-None-Match': rHit.headers.get('etag'),
|
|
},
|
|
}
|
|
)
|
|
expect(r304.status).toBe(304)
|
|
// ... Postponed but should not save 304 ...
|
|
await waitFor(1000)
|
|
|
|
// Now without cache headers should 200
|
|
const rStillFresh = await fetchViaHTTP(next.url, '/')
|
|
expect(rStillFresh.status).toBe(200)
|
|
})
|
|
})
|