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
284 lines
10 KiB
TypeScript
284 lines
10 KiB
TypeScript
/* eslint-env jest */
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
|
|
describe('nextjs APIs in after()', () => {
|
|
const { next, skipped, isNextDev } = nextTestSetup({
|
|
files: __dirname,
|
|
skipStart: true,
|
|
skipDeployment: true, // reading runtime logs is not supported in deploy tests
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
let currentCliOutputIndex = 0
|
|
|
|
const ignorePreviousLogs = () => {
|
|
currentCliOutputIndex = next.cliOutput.length
|
|
}
|
|
|
|
const getLogs = () => {
|
|
return next.cliOutput.slice(currentCliOutputIndex)
|
|
}
|
|
|
|
beforeEach(() => {
|
|
ignorePreviousLogs()
|
|
})
|
|
|
|
let buildLogs: string
|
|
beforeAll(async () => {
|
|
if (!isNextDev) {
|
|
await next.build()
|
|
buildLogs = next.cliOutput
|
|
} else {
|
|
buildLogs = '(no build logs in dev)'
|
|
}
|
|
await next.start()
|
|
})
|
|
|
|
describe('request APIs inside after()', () => {
|
|
// TODO(after): test unawaited calls, like this
|
|
//
|
|
// export default function Page() {
|
|
// const promise = headers()
|
|
// after(async () => {
|
|
// const headerStore = await promise
|
|
// })
|
|
// return null
|
|
// }
|
|
|
|
it('cannot be called in a dynamic page', async () => {
|
|
const path = '/request-apis/page-dynamic'
|
|
await next.render(path)
|
|
await retry(() => {
|
|
const logs = getLogs()
|
|
|
|
expect(logs).not.toContain(`[${path}] headers(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] headers(): error: Error: Route ${path} used \`headers()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] cookies(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] cookies(): error: Error: Route ${path} used \`cookies()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] connection(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] connection(): error: Error: Route ${path} used \`connection()\` inside \`after()\`.`
|
|
)
|
|
})
|
|
await retry(() => {
|
|
const logs = getLogs()
|
|
|
|
expect(logs).not.toContain(`[${path}] nested headers(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested headers(): error: Error: Route ${path} used \`headers()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] nested cookies(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested cookies(): error: Error: Route ${path} used \`cookies()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] nested connection(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested connection(): error: Error: Route ${path} used \`connection()\` inside \`after()\`.`
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('cannot be called in a prerendered page', () => {
|
|
it.each([
|
|
{
|
|
title: 'with `dynamic = "error"`',
|
|
path: '/request-apis/page-dynamic-error',
|
|
},
|
|
{
|
|
title: 'with `dynamic = "force-static"`',
|
|
path: '/request-apis/page-force-static',
|
|
},
|
|
])('$title', async ({ path }) => {
|
|
await next.render(path)
|
|
await retry(() => {
|
|
const logs = isNextDev ? getLogs() : buildLogs // in `next start` the error was logged at build time
|
|
|
|
expect(logs).not.toContain(`[${path}] headers(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] headers(): error: Error: Route ${path} used \`headers()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] cookies(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] cookies(): error: Error: Route ${path} used \`cookies()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] connection(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] connection(): error: Error: Route ${path} used \`connection()\` inside \`after()\`.`
|
|
)
|
|
})
|
|
await retry(() => {
|
|
const logs = isNextDev ? getLogs() : buildLogs // in `next start` the error was logged at build time
|
|
|
|
expect(logs).not.toContain(`[${path}] nested headers(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested headers(): error: Error: Route ${path} used \`headers()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] nested cookies(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested cookies(): error: Error: Route ${path} used \`cookies()\` inside \`after()\`. This is not supported.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] nested connection(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested connection(): error: Error: Route ${path} used \`connection()\` inside \`after()\`.`
|
|
)
|
|
})
|
|
})
|
|
})
|
|
|
|
it('can be called in a server action', async () => {
|
|
const path = '/request-apis/server-action'
|
|
const browser = await next.browser(path)
|
|
await browser.elementByCss('button[type="submit"]').click()
|
|
await retry(() => {
|
|
const logs = getLogs()
|
|
expect(logs).toContain(`[${path}] headers(): ok`)
|
|
expect(logs).toContain(`[${path}] nested headers(): ok`)
|
|
|
|
expect(logs).toContain(`[${path}] cookies(): ok`)
|
|
expect(logs).toContain(`[${path}] nested cookies(): ok`)
|
|
|
|
expect(logs).toContain(`[${path}] connection(): ok`)
|
|
expect(logs).toContain(`[${path}] nested connection(): ok`)
|
|
})
|
|
})
|
|
|
|
it('can be called in a dynamic route handler', async () => {
|
|
const path = '/request-apis/route-handler-dynamic'
|
|
await next.render(path)
|
|
await retry(() => {
|
|
const logs = getLogs()
|
|
expect(logs).toContain(`[${path}] headers(): ok`)
|
|
expect(logs).toContain(`[${path}] nested headers(): ok`)
|
|
|
|
expect(logs).toContain(`[${path}] cookies(): ok`)
|
|
expect(logs).toContain(`[${path}] nested cookies(): ok`)
|
|
|
|
expect(logs).toContain(`[${path}] connection(): ok`)
|
|
expect(logs).toContain(`[${path}] nested connection(): ok`)
|
|
})
|
|
})
|
|
|
|
it('can be called in a prerendered route handler with `dynamic = "force-static"`', async () => {
|
|
const path = '/request-apis/route-handler-force-static'
|
|
await next.render(path)
|
|
await retry(() => {
|
|
const logs = isNextDev ? getLogs() : buildLogs // in `next start` the error was logged at build time
|
|
expect(logs).toContain(`[${path}] headers(): ok`)
|
|
expect(logs).toContain(`[${path}] nested headers(): ok`)
|
|
|
|
expect(logs).toContain(`[${path}] cookies(): ok`)
|
|
expect(logs).toContain(`[${path}] nested cookies(): ok`)
|
|
|
|
expect(logs).toContain(`[${path}] connection(): ok`)
|
|
expect(logs).toContain(`[${path}] nested connection(): ok`)
|
|
})
|
|
})
|
|
|
|
it('can be called in a prerendered route handler with `dynamic = "error" (but throw, because dynamic should error)`', async () => {
|
|
const path = '/request-apis/route-handler-dynamic-error'
|
|
await next.render(path)
|
|
await retry(() => {
|
|
const logs = isNextDev ? getLogs() : buildLogs // in `next start` the error was logged at build time
|
|
|
|
expect(logs).not.toContain(`[${path}] headers(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] headers(): error: Error: Route ${path} with \`dynamic = "error"\` couldn't be rendered statically because it used \`headers()\`.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] nested headers(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested headers(): error: Error: Route ${path} with \`dynamic = "error"\` couldn't be rendered statically because it used \`headers()\`.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] cookies(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] cookies(): error: Error: Route ${path} with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies()\`.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] nested cookies(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested cookies(): error: Error: Route ${path} with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies()\`.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] connection(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] connection(): error: Error: Route ${path} with \`dynamic = "error"\` couldn't be rendered statically because it used \`connection()\`.`
|
|
)
|
|
|
|
expect(logs).not.toContain(`[${path}] nested connection(): ok`)
|
|
expect(logs).toContain(
|
|
`[${path}] nested connection(): error: Error: Route ${path} with \`dynamic = "error"\` couldn't be rendered statically because it used \`connection()\`.`
|
|
)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('draftMode status is readable, but cannot be changed', () => {
|
|
it.each([
|
|
{
|
|
title: 'dynamic page',
|
|
path: '/draft-mode/page-dynamic',
|
|
isDynamic: true,
|
|
},
|
|
{
|
|
title: 'static page',
|
|
path: '/draft-mode/page-static',
|
|
isDynamic: false,
|
|
},
|
|
{
|
|
title: 'dynamic route handler',
|
|
path: '/draft-mode/route-handler-dynamic',
|
|
isDynamic: true,
|
|
},
|
|
{
|
|
title: 'static route handler',
|
|
path: '/draft-mode/route-handler-static',
|
|
isDynamic: false,
|
|
},
|
|
])('$title', async ({ path, isDynamic }) => {
|
|
await next.render(path)
|
|
await retry(() => {
|
|
// in `next start`, static routes log the error at build time
|
|
const logs = isDynamic || isNextDev ? getLogs() : buildLogs
|
|
expect(logs).toContain(`[${path}] draft.isEnabled: false`)
|
|
expect(logs).toContain(
|
|
`Route ${path} used "draftMode().enable()" inside \`after()\``
|
|
)
|
|
expect(logs).toContain(
|
|
`Route ${path} used "draftMode().disable()" inside \`after()\``
|
|
)
|
|
})
|
|
})
|
|
|
|
it('server action', async () => {
|
|
const path = '/draft-mode/server-action'
|
|
const browser = await next.browser(path)
|
|
await browser.elementByCss('button[type="submit"]').click()
|
|
await retry(() => {
|
|
const logs = getLogs()
|
|
expect(logs).toContain(`[${path}] draft.isEnabled: false`)
|
|
expect(logs).toContain(
|
|
`Route ${path} used "draftMode().enable()" inside \`after()\``
|
|
)
|
|
expect(logs).toContain(
|
|
`Route ${path} used "draftMode().disable()" inside \`after()\``
|
|
)
|
|
})
|
|
})
|
|
})
|
|
})
|