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:
parent
557084a331
commit
26a35a4798
6 changed files with 47 additions and 0 deletions
12
test/e2e/edge-pages-support/app/pages/api/[id].js
Normal file
12
test/e2e/edge-pages-support/app/pages/api/[id].js
Normal 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),
|
||||
})
|
||||
)
|
||||
}
|
12
test/e2e/edge-pages-support/app/pages/api/hello.js
Normal file
12
test/e2e/edge-pages-support/app/pages/api/hello.js
Normal 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),
|
||||
})
|
||||
)
|
||||
}
|
|
@ -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 () => {
|
||||
const html = await renderViaHTTP(next.url, '/')
|
||||
const $ = cheerio.load(html)
|
Loading…
Reference in a new issue