mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Preparation for removing `process.env.TURBOPACK` being added to Turbopack tests. That way we can properly test `next start` without `process.env.TURBOPACK` being set. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
136 lines
4.7 KiB
TypeScript
136 lines
4.7 KiB
TypeScript
import { createNext, FileRef } from 'e2e-utils'
|
|
import { NextInstance } from 'e2e-utils'
|
|
import { fetchViaHTTP, File, nextBuild } from 'next-test-utils'
|
|
import { join } from 'path'
|
|
import stripAnsi from 'strip-ansi'
|
|
|
|
const pagePath = 'pages/index.jsx'
|
|
const apiPath = 'pages/api/edge.js'
|
|
|
|
;(process.env.IS_TURBOPACK_TEST ? describe.skip.each : describe.each)([
|
|
{ appDir: join(__dirname, './app/src'), title: 'src/pages and API routes' },
|
|
{ appDir: join(__dirname, './app'), title: 'pages and API routes' },
|
|
])('Configurable runtime for $title', ({ appDir }) => {
|
|
let next: NextInstance
|
|
const page = new File(join(appDir, pagePath))
|
|
const api = new File(join(appDir, apiPath))
|
|
|
|
if ((global as any).isNextDev) {
|
|
describe('In development mode', () => {
|
|
beforeAll(async () => {
|
|
next = await createNext({
|
|
files: new FileRef(appDir),
|
|
dependencies: {},
|
|
skipStart: true,
|
|
})
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await next.stop()
|
|
await next.patchFile(pagePath, page.originalContent)
|
|
await next.patchFile(apiPath, api.originalContent)
|
|
})
|
|
|
|
afterAll(() => next.destroy())
|
|
|
|
it('runs with no warning API route on the edge runtime', async () => {
|
|
await next.start()
|
|
const res = await fetchViaHTTP(next.url, `/api/edge`)
|
|
expect(res.status).toEqual(200)
|
|
expect(next.cliOutput).not.toInclude('error')
|
|
expect(next.cliOutput).not.toInclude('warn')
|
|
})
|
|
|
|
it('warns about API route using experimental-edge runtime', async () => {
|
|
await next.patchFile(
|
|
apiPath,
|
|
`
|
|
export default () => new Response('ok');
|
|
export const config = { runtime: 'experimental-edge' };
|
|
`
|
|
)
|
|
await next.start()
|
|
const res = await fetchViaHTTP(next.url, `/api/edge`)
|
|
expect(res.status).toEqual(200)
|
|
expect(next.cliOutput).not.toInclude('error')
|
|
expect(stripAnsi(next.cliOutput)).toInclude(
|
|
`/api/edge provided runtime 'experimental-edge'. It can be updated to 'edge' instead.`
|
|
)
|
|
})
|
|
it('warns about page using edge runtime', async () => {
|
|
await next.patchFile(
|
|
pagePath,
|
|
`
|
|
export default () => (<p>hello world</p>);
|
|
export const runtime = 'experimental-edge';
|
|
`
|
|
)
|
|
await next.start()
|
|
const res = await fetchViaHTTP(next.url, `/`)
|
|
expect(res.status).toEqual(200)
|
|
expect(next.cliOutput).not.toInclude('error')
|
|
expect(stripAnsi(next.cliOutput)).toInclude(
|
|
`You are using an experimental edge runtime, the API might change.`
|
|
)
|
|
})
|
|
|
|
it('errors about page using edge runtime', async () => {
|
|
await next.patchFile(
|
|
pagePath,
|
|
`
|
|
export default () => (<p>hello world</p>);
|
|
export const runtime = 'edge';
|
|
`
|
|
)
|
|
await next.start()
|
|
const res = await fetchViaHTTP(next.url, `/`)
|
|
expect(res.status).toEqual(200)
|
|
expect(stripAnsi(next.cliOutput)).toInclude(
|
|
`Page / provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
|
|
)
|
|
expect(next.cliOutput).not.toInclude('warn')
|
|
})
|
|
})
|
|
} else if ((global as any).isNextStart) {
|
|
describe('In start mode', () => {
|
|
// TODO because createNext runs process.exit() without any log info on build failure, rely on good old nextBuild()
|
|
afterEach(async () => {
|
|
page.restore()
|
|
api.restore()
|
|
})
|
|
|
|
it('builds with API route on the edge runtime and page on the experimental edge runtime', async () => {
|
|
page.write(`
|
|
export default () => (<p>hello world</p>);
|
|
export const runtime = 'experimental-edge';
|
|
`)
|
|
const output = await nextBuild(appDir, undefined, {
|
|
stdout: true,
|
|
stderr: true,
|
|
})
|
|
expect(output.code).toBe(0)
|
|
expect(output.stderr).not.toContain(`error`)
|
|
expect(output.stdout).not.toContain(`warn`)
|
|
})
|
|
|
|
it('does not build with page on the edge runtime', async () => {
|
|
page.write(`
|
|
export default () => (<p>hello world</p>);
|
|
export const runtime = 'edge';
|
|
`)
|
|
const output = await nextBuild(appDir, undefined, {
|
|
stdout: true,
|
|
stderr: true,
|
|
})
|
|
expect(output.code).toBe(1)
|
|
expect(output.stderr).not.toContain(`Build failed`)
|
|
expect(stripAnsi(output.stderr)).toContain(
|
|
`Error: Page / provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
|
|
)
|
|
})
|
|
})
|
|
} else {
|
|
it.skip('no deploy tests', () => {})
|
|
}
|
|
})
|