Files
vercel__next.js/test/development/acceptance-app/rsc-build-errors-next-apis.test.ts
Benjamin Woodruff a87692e17c [ci] Split up large rsc-build-errors development test (#95624)
See https://github.com/vercel/next.js/pull/95553 for an explanation of
why we want to split these up. TL;DR it makes CI faster and saves us
some money.

In CI we have to run tests at the suite/file granularity, so if a test
suite is too long it limits parallelism and if it has to be retried, we
have to retry the full suite.
2026-07-08 19:56:27 -07:00

87 lines
3.3 KiB
TypeScript

import { createSandbox } from 'development-sandbox'
import { runRscBuildErrorsTests } from './rsc-build-errors.util'
runRscBuildErrorsTests(({ next, isTurbopack, isRspack }) => {
describe("importing 'next/cache' APIs in a client component", () => {
test.each(['revalidatePath', 'revalidateTag', 'cacheLife', 'cacheTag'])(
'%s is not allowed',
async (api) => {
await using sandbox = await createSandbox(
next,
undefined,
`/server-with-errors/next-cache-in-client/${api.toLowerCase()}`
)
const { session } = sandbox
await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude(
`You're importing a module that depends on "${api}" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component.`
)
}
)
test.each([
'unstable_cache', // useless in client, but doesn't technically error
'unstable_noStore', // no-op in client, but allowed for legacy reasons
])('%s is allowed', async (api) => {
await using sandbox = await createSandbox(
next,
undefined,
`/server-with-errors/next-cache-in-client/${api.toLowerCase()}`
)
const { session } = sandbox
await session.waitForNoRedbox()
})
})
describe('next/root-params', () => {
it("importing a non-existent getter from 'next/root-params'", async () => {
await using sandbox = await createSandbox(
next,
undefined,
`/server-with-errors/next-root-params/without-flag`
)
const { session } = sandbox
await session.waitForRedbox()
if (isTurbopack) {
expect(await session.getRedboxSource()).toInclude(
`Export whatever doesn't exist in target module`
)
} else if (isRspack) {
expect(await session.getRedboxDescription()).toInclude(
`'whatever' is not exported from 'next/root-params'`
)
} else {
expect(await session.getRedboxDescription()).toInclude(
`whatever) is not a function`
)
}
})
it("importing 'next/root-params' in a client component", async () => {
await using sandbox = await createSandbox(
next,
undefined,
`/server-with-errors/next-root-params/in-client`
)
const { session } = sandbox
await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude(
`You're importing a module that depends on "next/root-params" into a React Client Component module. This API is only available in Server Components but one of its parents is marked with "use client", so this module is also a Client Component.`
)
})
it("importing 'next/root-params' in a client component in a way that bypasses import analysis", async () => {
await using sandbox = await createSandbox(
next,
undefined,
`/server-with-errors/next-root-params/in-client-await-import`
)
const { session } = sandbox
await session.waitForRedbox()
expect(await session.getRedboxSource()).toInclude(
`'next/root-params' cannot be imported from a Client Component module. It should only be used from a Server Component.`
)
})
})
})