Skip to content

Commit adc8d2d

Browse files
committed
Update test snapshots for alternative bundler [4/n]
Test Plan: `pnpm test-dev-rspack test/development/acceptance/server-component-compiler-errors-in-pages.test.ts` passes
1 parent 208fd5f commit adc8d2d

File tree

1 file changed

+75
-10
lines changed

1 file changed

+75
-10
lines changed

test/development/acceptance/server-component-compiler-errors-in-pages.test.ts

+75-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { nextTestSetup } from 'e2e-utils'
33
import { createSandbox } from 'development-sandbox'
44
import { outdent } from 'outdent'
55

6+
const isRspack = process.env.NEXT_RSPACK !== undefined
7+
68
const initialFiles = new Map([
79
['app/_.js', ''], // app dir need to exists, otherwise the SWC RSC checks will not run
810
[
@@ -62,18 +64,39 @@ describe('Error Overlay for server components compiler errors in pages', () => {
6264
6365
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"
6466
`)
67+
} else if (isRspack) {
68+
expect(
69+
takeUpToString(
70+
next.normalizeTestDirContent(await session.getRedboxSource()),
71+
'----'
72+
)
73+
).toMatchInlineSnapshot(`
74+
"./components/Comp.js
75+
× Module build failed:
76+
╰─▶ × 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-
77+
│ | your-application/rendering/server-components
78+
│ |
79+
│ |
80+
│ ,-[1:1]
81+
│ 1 | import { cookies } from 'next/headers'
82+
│ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
│ 2 |
84+
│ 3 | export default function Page() {
85+
│ 4 | return <p>hello world</p>
86+
│ \`----"
87+
`)
6588
} else {
6689
expect(next.normalizeTestDirContent(await session.getRedboxSource()))
6790
.toMatchInlineSnapshot(`
6891
"./components/Comp.js
6992
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-
7093
| your-application/rendering/server-components
71-
|
72-
|
94+
|
95+
|
7396
,-[1:1]
7497
1 | import { cookies } from 'next/headers'
7598
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76-
2 |
99+
2 |
77100
3 | export default function Page() {
78101
4 | return <p>hello world</p>
79102
\`----
@@ -118,6 +141,27 @@ describe('Error Overlay for server components compiler errors in pages', () => {
118141
119142
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"
120143
`)
144+
} else if (isRspack) {
145+
expect(
146+
takeUpToString(
147+
next.normalizeTestDirContent(await session.getRedboxSource()),
148+
'----'
149+
)
150+
).toMatchInlineSnapshot(`
151+
"./components/Comp.js
152+
× Module build failed:
153+
╰─▶ × 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-
154+
│ | application/rendering/server-components
155+
│ |
156+
│ |
157+
│ ,-[1:1]
158+
│ 1 | import 'server-only'
159+
│ : ^^^^^^^^^^^^^^^^^^^^
160+
│ 2 |
161+
│ 3 | export default function Page() {
162+
│ 4 | return 'hello world'
163+
│ \`----"
164+
`)
121165
} else {
122166
expect(
123167
takeUpToString(
@@ -128,12 +172,12 @@ describe('Error Overlay for server components compiler errors in pages', () => {
128172
"./components/Comp.js
129173
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-
130174
| application/rendering/server-components
131-
|
132-
|
175+
|
176+
|
133177
,-[1:1]
134178
1 | import 'server-only'
135179
: ^^^^^^^^^^^^^^^^^^^^
136-
2 |
180+
2 |
137181
3 | export default function Page() {
138182
4 | return 'hello world'
139183
\`----
@@ -176,6 +220,27 @@ describe('Error Overlay for server components compiler errors in pages', () => {
176220
177221
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"
178222
`)
223+
} else if (isRspack) {
224+
expect(
225+
takeUpToString(
226+
next.normalizeTestDirContent(await session.getRedboxSource()),
227+
'----'
228+
)
229+
).toMatchInlineSnapshot(`
230+
"./components/Comp.js
231+
× Module build failed:
232+
╰─▶ × 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-
233+
│ | application/rendering/server-components
234+
│ |
235+
│ |
236+
│ ,-[1:1]
237+
│ 1 | import { after } from 'next/server'
238+
│ : ^^^^^
239+
│ 2 |
240+
│ 3 | export default function Page() {
241+
│ 4 | return 'hello world'
242+
│ \`----"
243+
`)
179244
} else {
180245
expect(
181246
takeUpToString(
@@ -186,12 +251,12 @@ describe('Error Overlay for server components compiler errors in pages', () => {
186251
"./components/Comp.js
187252
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-
188253
| application/rendering/server-components
189-
|
190-
|
254+
|
255+
|
191256
,-[1:1]
192257
1 | import { after } from 'next/server'
193258
: ^^^^^
194-
2 |
259+
2 |
195260
3 | export default function Page() {
196261
4 | return 'hello world'
197262
\`----
@@ -241,7 +306,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
241306
'components/Comp.js',
242307
outdent`
243308
import { ${api} } from 'next/cache'
244-
309+
245310
export default function Page() {
246311
return 'hello world'
247312
}

0 commit comments

Comments
 (0)