Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
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', () => {})
|
|
}
|
|
})
|