mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +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]>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import { fetchViaHTTP } from 'next-test-utils'
|
|
|
|
describe('Rewritten API Requests should pass OPTIONS requests to the api function', () => {
|
|
const { next } = nextTestSetup({
|
|
files: {
|
|
'pages/api/some-endpoint.js': `
|
|
export default (req, res) => {
|
|
res.end("successfully hit some-endpoint!")
|
|
}
|
|
`,
|
|
},
|
|
nextConfig: {
|
|
rewrites: () =>
|
|
Promise.resolve({
|
|
beforeFiles: [
|
|
// Nextjs by default requires a /api prefix, let's remove that
|
|
{
|
|
source: '/:path*',
|
|
destination: '/api/:path*',
|
|
},
|
|
],
|
|
afterFiles: [],
|
|
fallback: [],
|
|
}),
|
|
},
|
|
dependencies: {},
|
|
})
|
|
|
|
it('should pass OPTIONS requests to the api function', async () => {
|
|
const res = await fetchViaHTTP(next.url, '/some-endpoint', null, {
|
|
method: 'OPTIONS',
|
|
headers: {
|
|
Origin: 'http://localhost:3000',
|
|
},
|
|
})
|
|
expect(await res.text()).toContain('successfully hit some-endpoint!')
|
|
})
|
|
})
|