|
|
import { createNext, FileRef } from 'e2e-utils' |
|
|
import { NextInstance } from 'e2e-utils' |
|
|
import { join } from 'path' |
|
|
import { fetchViaHTTP, waitFor } from 'next-test-utils' |
|
|
|
|
|
describe('app-dir-prevent-304-caching', () => { |
|
|
let next: NextInstance |
|
|
|
|
|
beforeAll(async () => { |
|
|
next = await createNext({ |
|
|
files: { |
|
|
'next.config.js': new FileRef(join(__dirname, 'next.config.js')), |
|
|
app: new FileRef(join(__dirname, 'app')), |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
afterAll(() => next.destroy()) |
|
|
|
|
|
|
|
|
it('should not cache 304 status', async () => { |
|
|
|
|
|
const rFresh = await fetchViaHTTP(next.url, '/') |
|
|
expect(rFresh.status).toBe(200) |
|
|
|
|
|
await waitFor(500) |
|
|
|
|
|
|
|
|
const rHit = await fetchViaHTTP( |
|
|
next.url, |
|
|
'/', |
|
|
{}, |
|
|
{ |
|
|
headers: { |
|
|
'If-None-Match': rFresh.headers.get('etag'), |
|
|
}, |
|
|
} |
|
|
) |
|
|
expect(rHit.status).toBe(200) |
|
|
await waitFor(500) |
|
|
|
|
|
|
|
|
const r304 = await fetchViaHTTP( |
|
|
next.url, |
|
|
'/', |
|
|
{}, |
|
|
{ |
|
|
headers: { |
|
|
'If-None-Match': rHit.headers.get('etag'), |
|
|
}, |
|
|
} |
|
|
) |
|
|
expect(r304.status).toBe(304) |
|
|
|
|
|
await waitFor(1000) |
|
|
|
|
|
|
|
|
const rStillFresh = await fetchViaHTTP(next.url, '/') |
|
|
expect(rStillFresh.status).toBe(200) |
|
|
}) |
|
|
}) |
|
|
|