Skip to content

Commit

Permalink
Update test snapshots for alternative bundler [4/n]
Browse files Browse the repository at this point in the history
Test Plan: `pnpm test-dev-rspack test/development/acceptance/server-component-compiler-errors-in-pages.test.ts` passes
  • Loading branch information
wbinnssmith committed Feb 27, 2025
1 parent 208fd5f commit adc8d2d
Showing 1 changed file with 75 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { nextTestSetup } from 'e2e-utils'
import { createSandbox } from 'development-sandbox'
import { outdent } from 'outdent'

const isRspack = process.env.NEXT_RSPACK !== undefined

const initialFiles = new Map([
['app/_.js', ''], // app dir need to exists, otherwise the SWC RSC checks will not run
[
Expand Down Expand Up @@ -62,18 +64,39 @@ describe('Error Overlay for server components compiler errors in pages', () => {
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/app/building-your-application/rendering/server-components"
`)
} else if (isRspack) {
expect(
takeUpToString(
next.normalizeTestDirContent(await session.getRedboxSource()),
'----'
)
).toMatchInlineSnapshot(`
"./components/Comp.js
× Module build failed:
╰─▶ × 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/app/building-
│ | your-application/rendering/server-components
│ |
│ |
│ ,-[1:1]
│ 1 | import { cookies } from 'next/headers'
│ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ 2 |
│ 3 | export default function Page() {
│ 4 | return <p>hello world</p>
│ \`----"
`)
} 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/app/building-
| your-application/rendering/server-components
|
|
|
|
,-[1:1]
1 | import { cookies } from 'next/headers'
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 |
2 |
3 | export default function Page() {
4 | return <p>hello world</p>
\`----
Expand Down Expand Up @@ -118,6 +141,27 @@ describe('Error Overlay for server components compiler errors in pages', () => {
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/app/building-your-application/rendering/server-components"
`)
} else if (isRspack) {
expect(
takeUpToString(
next.normalizeTestDirContent(await session.getRedboxSource()),
'----'
)
).toMatchInlineSnapshot(`
"./components/Comp.js
× Module build failed:
╰─▶ × 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/app/building-your-
│ | application/rendering/server-components
│ |
│ |
│ ,-[1:1]
│ 1 | import 'server-only'
│ : ^^^^^^^^^^^^^^^^^^^^
│ 2 |
│ 3 | export default function Page() {
│ 4 | return 'hello world'
│ \`----"
`)
} else {
expect(
takeUpToString(
Expand All @@ -128,12 +172,12 @@ describe('Error Overlay for server components compiler errors in pages', () => {
"./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/app/building-your-
| application/rendering/server-components
|
|
|
|
,-[1:1]
1 | import 'server-only'
: ^^^^^^^^^^^^^^^^^^^^
2 |
2 |
3 | export default function Page() {
4 | return 'hello world'
\`----
Expand Down Expand Up @@ -176,6 +220,27 @@ describe('Error Overlay for server components compiler errors in pages', () => {
You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components"
`)
} else if (isRspack) {
expect(
takeUpToString(
next.normalizeTestDirContent(await session.getRedboxSource()),
'----'
)
).toMatchInlineSnapshot(`
"./components/Comp.js
× Module build failed:
╰─▶ × Error: x You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-
│ | application/rendering/server-components
│ |
│ |
│ ,-[1:1]
│ 1 | import { after } from 'next/server'
│ : ^^^^^
│ 2 |
│ 3 | export default function Page() {
│ 4 | return 'hello world'
│ \`----"
`)
} else {
expect(
takeUpToString(
Expand All @@ -186,12 +251,12 @@ describe('Error Overlay for server components compiler errors in pages', () => {
"./components/Comp.js
Error: x You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-
| application/rendering/server-components
|
|
|
|
,-[1:1]
1 | import { after } from 'next/server'
: ^^^^^
2 |
2 |
3 | export default function Page() {
4 | return 'hello world'
\`----
Expand Down Expand Up @@ -241,7 +306,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
'components/Comp.js',
outdent`
import { ${api} } from 'next/cache'
export default function Page() {
return 'hello world'
}
Expand Down

0 comments on commit adc8d2d

Please sign in to comment.