From 997235da31a1ec513541d7fb9ecd336f770322ef Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 10 Oct 2024 13:56:53 -0400 Subject: [PATCH] Add basic smoke test for per-segment fetching We can't test per-segment fetching end-to-end yet because the client behavior hasn't been implemented. These are basic smoke tests to demonstrate that the server correctly responds to a request. We will replace them with proper e2e tests once more of the feature has been implemented. --- .../simple/per-segment-prefetching.test.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/e2e/app-dir/ppr-navigations/simple/per-segment-prefetching.test.ts diff --git a/test/e2e/app-dir/ppr-navigations/simple/per-segment-prefetching.test.ts b/test/e2e/app-dir/ppr-navigations/simple/per-segment-prefetching.test.ts new file mode 100644 index 00000000000000..413f55bfcff4a2 --- /dev/null +++ b/test/e2e/app-dir/ppr-navigations/simple/per-segment-prefetching.test.ts @@ -0,0 +1,46 @@ +import { nextTestSetup } from 'e2e-utils' + +describe('per segment prefetching', () => { + if ((global as any).isNextDev) { + test('ppr is disabled in dev', () => {}) + return + } + + const { next } = nextTestSetup({ + files: __dirname, + }) + + // This feature is only partially implemented; the client does not yet issue + // these types of requests. This tests that the server responds correctly. + // TODO: Replace with e2e tests once more is implemented. + + it('prefetch an individual segment', async () => { + const response = await next.fetch('/en', { + headers: { + RSC: '1', + 'Next-Router-Prefetch': '1', + 'Next-Router-Segment-Prefetch': '/', + }, + }) + expect(response.status).toBe(200) + const responseText = await response.text() + expect(responseText.trim()).toBe( + // The actual data is not yet generated, but this indicates that the + // request was handled correctly. + 'TODO (Per Segment Prefetching): Not yet implemented' + ) + }) + + it('respond with 404 if the segment does not have prefetch data', async () => { + const response = await next.fetch('/en', { + headers: { + RSC: '1', + 'Next-Router-Prefetch': '1', + 'Next-Router-Segment-Prefetch': '/does-not-exist', + }, + }) + expect(response.status).toBe(404) + const responseText = await response.text() + expect(responseText.trim()).toBe('') + }) +})