mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
* https://github.com/vercel/turbo/pull/7437 <!-- Tobias Koppers - report relative start/end and fix start time for events --> * https://github.com/vercel/turbo/pull/7446 <!-- Tobias Koppers - allow to aggregate all spans --> * https://github.com/vercel/turbo/pull/6651 <!-- max - fix(postcss_configs): support for resolve `postcss.config.json` file --> * https://github.com/vercel/turbo/pull/7448 <!-- Leah - chore: remove "rust" npm package --> * https://github.com/vercel/turbo/pull/7436 <!-- Leah - refactor(turbo-tasks-fs): move file watching into separate file --> * https://github.com/vercel/turbo/pull/7396 <!-- Donny/강동윤 - feat(turbopack): Apply critical ES lint rules --> * https://github.com/vercel/turbo/pull/7421 <!-- Donny/강동윤 - fix(turbopack): Use different title for non-parsing issues --> * https://github.com/vercel/turbo/pull/7501 <!-- Tobias Koppers - Tracing: Report progress on initial read --> * https://github.com/vercel/turbo/pull/7508 <!-- Donny/강동윤 - fix(turbopack): Fix CSS Modules of turbopack in swc mode --> * https://github.com/vercel/turbo/pull/7424 <!-- Donny/강동윤 - fix(turbopack): Analyze for-of stmts to allow using `sharp` --> * https://github.com/vercel/turbo/pull/7510 <!-- Tobias Koppers - dedupe primary_modules to avoid deduping in chunking, reduce memory usage --> * https://github.com/vercel/turbo/pull/7509 <!-- Tobias Koppers - split graph_node_to_referenced_nodes into cacheable and non-cacheable parts --> * https://github.com/vercel/turbo/pull/7516 <!-- Tobias Koppers - fix ignore in package.json --> * https://github.com/vercel/turbo/pull/7500 <!-- Tobias Koppers - add span count to trace-server --> * https://github.com/vercel/turbo/pull/7507 <!-- Donny/강동윤 - fix(turbopack): Fix CSS module purity validator -->
154 lines
4.7 KiB
TypeScript
154 lines
4.7 KiB
TypeScript
/* eslint-env jest */
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import { check } from 'next-test-utils'
|
|
import { sandbox } from 'development-sandbox'
|
|
import { outdent } from 'outdent'
|
|
|
|
const initialFiles = new Map([
|
|
['app/_.js', ''], // app dir need to exists, otherwise the SWC RSC checks will not run
|
|
[
|
|
'pages/index.js',
|
|
outdent`
|
|
import Comp from '../components/Comp'
|
|
|
|
export default function Page() { return <Comp /> }
|
|
`,
|
|
],
|
|
[
|
|
'components/Comp.js',
|
|
outdent`
|
|
export default function Comp() {
|
|
return <p>Hello world</p>
|
|
}
|
|
`,
|
|
],
|
|
])
|
|
|
|
describe('Error Overlay for server components compiler errors in pages', () => {
|
|
const { next } = nextTestSetup({
|
|
files: {},
|
|
dependencies: {
|
|
react: 'latest',
|
|
'react-dom': 'latest',
|
|
},
|
|
skipStart: true,
|
|
})
|
|
|
|
test("importing 'next/headers' in pages", async () => {
|
|
const { session, cleanup } = await sandbox(next, initialFiles)
|
|
|
|
await session.patch(
|
|
'components/Comp.js',
|
|
outdent`
|
|
import { cookies } from 'next/headers'
|
|
|
|
export default function Page() {
|
|
return <p>hello world</p>
|
|
}
|
|
`
|
|
)
|
|
|
|
expect(await session.hasRedbox()).toBe(true)
|
|
await check(
|
|
() => session.getRedboxSource(),
|
|
/That only works in a Server Component/
|
|
)
|
|
|
|
if (process.env.TURBOPACK) {
|
|
expect(next.normalizeTestDirContent(await session.getRedboxSource()))
|
|
.toMatchInlineSnapshot(`
|
|
"./components/Comp.js:1:1
|
|
Ecmascript file had an error
|
|
> 1 | import { cookies } from 'next/headers'
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
2 |
|
|
3 | export default function Page() {
|
|
4 | return <p>hello world</p>
|
|
|
|
You're importing a component that needs next/headers. That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/react-essentials#server-components"
|
|
`)
|
|
} else {
|
|
expect(next.normalizeTestDirContent(await session.getRedboxSource()))
|
|
.toMatchInlineSnapshot(`
|
|
"./components/Comp.js
|
|
Error:
|
|
x You're importing a component that needs next/headers. That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/
|
|
| react-essentials#server-components
|
|
|
|
|
|
|
|
,-[TEST_DIR/components/Comp.js:1:1]
|
|
1 | import { cookies } from 'next/headers'
|
|
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
2 |
|
|
3 | export default function Page() {
|
|
4 | return <p>hello world</p>
|
|
\`----
|
|
|
|
Import trace for requested module:
|
|
./components/Comp.js
|
|
./pages/index.js"
|
|
`)
|
|
}
|
|
|
|
await cleanup()
|
|
})
|
|
|
|
test("importing 'server-only' in pages", async () => {
|
|
const { session, cleanup } = await sandbox(next, initialFiles)
|
|
|
|
await next.patchFile(
|
|
'components/Comp.js',
|
|
outdent`
|
|
import 'server-only'
|
|
|
|
export default function Page() {
|
|
return 'hello world'
|
|
}
|
|
`
|
|
)
|
|
|
|
expect(await session.hasRedbox()).toBe(true)
|
|
await check(
|
|
() => session.getRedboxSource(),
|
|
/That only works in a Server Component/
|
|
)
|
|
|
|
if (process.env.TURBOPACK) {
|
|
expect(next.normalizeTestDirContent(await session.getRedboxSource()))
|
|
.toMatchInlineSnapshot(`
|
|
"./components/Comp.js:1:1
|
|
Ecmascript file had an error
|
|
> 1 | import 'server-only'
|
|
| ^^^^^^^^^^^^^^^^^^^^
|
|
2 |
|
|
3 | export default function Page() {
|
|
4 | return 'hello world'
|
|
|
|
You're importing a component that needs server-only. That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/react-essentials#server-components"
|
|
`)
|
|
} else {
|
|
expect(next.normalizeTestDirContent(await session.getRedboxSource()))
|
|
.toMatchInlineSnapshot(`
|
|
"./components/Comp.js
|
|
Error:
|
|
x You're importing a component that needs server-only. That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/
|
|
| react-essentials#server-components
|
|
|
|
|
|
|
|
,-[TEST_DIR/components/Comp.js:1:1]
|
|
1 | import 'server-only'
|
|
: ^^^^^^^^^^^^^^^^^^^^
|
|
2 |
|
|
3 | export default function Page() {
|
|
4 | return 'hello world'
|
|
\`----
|
|
|
|
Import trace for requested module:
|
|
./components/Comp.js
|
|
./pages/index.js"
|
|
`)
|
|
}
|
|
await cleanup()
|
|
})
|
|
})
|