Files
66478522a8 Improve RSC error messages (#90702)
Improve the RSC error messages to be more comprehensive.

x-ref:
https://github.com/vercel/next.js/pull/89688#discussion_r2865847895

---------

Co-authored-by: Claude Haiku 4.5 <[email protected]>
2026-03-17 14:37:26 +01:00

35 lines
1.2 KiB
TypeScript

/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import * as Log from './basic/utils/log'
import { waitForRedbox, getRedboxSource } from '../../../lib/next-test-utils'
import { join } from 'path'
describe('after() - invalid usages', () => {
const { next } = nextTestSetup({
files: join(__dirname, 'basic'),
})
let currentCliOutputIndex = 0
beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length
})
const getAfterLogs = () => {
if (next.cliOutput.length < currentCliOutputIndex) {
// cliOutput shrank since we started the test, so something (like a `sandbox`) reset the logs
currentCliOutputIndex = 0
}
return Log.readCliLogs(next.cliOutput.slice(currentCliOutputIndex))
}
it('errors at compile time when used in a client module', async () => {
const session = await next.browser('/invalid-in-client')
await waitForRedbox(session)
expect(await getRedboxSource(session)).toMatch(
/You're importing a module that depends on "?after"? 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\./
)
expect(getAfterLogs()).toHaveLength(0)
})
})