mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## What? Converts existing `createNext()` usage into `nextTestSetup()`. `createNext()` was the setup step we had before `nextTestSetup()` was added. This PR focused on the simple conversion cases. There will be a follow-up to complete the last few. --------- Co-authored-by: Cursor <[email protected]>
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
import { fetchViaHTTP } from 'next-test-utils'
|
|
import path from 'path'
|
|
|
|
describe('Edge API endpoints can receive body', () => {
|
|
const { next } = nextTestSetup({
|
|
files: {
|
|
'pages/api/edge.js': new FileRef(
|
|
path.resolve(__dirname, './app/pages/api/edge.js')
|
|
),
|
|
'pages/api/index.js': new FileRef(
|
|
path.resolve(__dirname, './app/pages/api/index.js')
|
|
),
|
|
},
|
|
dependencies: {},
|
|
})
|
|
|
|
it('reads the body as text', async () => {
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/edge',
|
|
{},
|
|
{
|
|
body: 'hello, world.',
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(await res.text()).toBe('got: hello, world.')
|
|
})
|
|
|
|
it('reads the body from index', async () => {
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api',
|
|
{},
|
|
{
|
|
body: 'hello, world.',
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(await res.text()).toBe('got: hello, world.')
|
|
})
|
|
})
|