Skip to content

Commit

Permalink
Add basic smoke test for per-segment fetching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Oct 11, 2024
1 parent 360a1a5 commit f32883c
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { nextTestSetup } from 'e2e-utils'

describe('per segment prefetching', () => {
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
})

if (isNextDev || isNextDeploy) {
test('ppr is disabled', () => {})
return
}

// 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('')
})
})

0 comments on commit f32883c

Please sign in to comment.