Add test coverage for pages edge API routes (#48370)

Ensures we have coverage for edge API routes in pages so we don't
regress.

Closes: https://github.com/vercel/next.js/issues/48263
This commit is contained in:
JJ Kasper 2023-04-13 22:07:54 -07:00 committed by GitHub
parent 557084a331
commit 26a35a4798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,12 @@
export const config = {
runtime: 'edge',
}
export default async function handler(req) {
return new Response(
JSON.stringify({
hello: 'again',
query: Object.fromEntries(req.nextUrl.searchParams),
})
)
}

View file

@ -0,0 +1,12 @@
export const config = {
runtime: 'edge',
}
export default async function handler(req) {
return new Response(
JSON.stringify({
hello: 'world',
query: Object.fromEntries(req.nextUrl.searchParams),
})
)
}

View file

@ -39,6 +39,29 @@ describe('edge-render-getserversideprops', () => {
}) })
} }
it('should have correct query for pages/api', async () => {
const res = await fetchViaHTTP(next.url, '/api/hello', { a: 'b' })
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
hello: 'world',
query: {
a: 'b',
},
})
})
it('should have correct query for pages/api dynamic', async () => {
const res = await fetchViaHTTP(next.url, '/api/id-1', { a: 'b' })
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
hello: 'again',
query: {
a: 'b',
id: 'id-1',
},
})
})
it('should have correct query/params on index', async () => { it('should have correct query/params on index', async () => {
const html = await renderViaHTTP(next.url, '/') const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html) const $ = cheerio.load(html)