Skip to content

Commit ff35295

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 c929afc commit ff35295

File tree

1 file changed

+111
-46
lines changed

1 file changed

+111
-46
lines changed

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

+111-46
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,25 +64,46 @@ 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(`
68-
"./components/Comp.js
69-
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-
70-
| your-application/rendering/server-components
71-
|
72-
|
73-
,-[1:1]
74-
1 | import { cookies } from 'next/headers'
75-
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76-
2 |
77-
3 | export default function Page() {
78-
4 | return <p>hello world</p>
79-
\`----
80-
81-
Import trace for requested module:
82-
./components/Comp.js
83-
./pages/index.js"
91+
"./components/Comp.js
92+
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-
93+
| your-application/rendering/server-components
94+
|
95+
|
96+
,-[1:1]
97+
1 | import { cookies } from 'next/headers'
98+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99+
2 |
100+
3 | export default function Page() {
101+
4 | return <p>hello world</p>
102+
\`----
103+
104+
Import trace for requested module:
105+
./components/Comp.js
106+
./pages/index.js"
84107
`)
85108
}
86109
})
@@ -118,28 +141,49 @@ 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(
124168
next.normalizeTestDirContent(await session.getRedboxSource()),
125169
'Import trace for requested module:'
126170
)
127171
).toMatchInlineSnapshot(`
128-
"./components/Comp.js
129-
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-
130-
| application/rendering/server-components
131-
|
132-
|
133-
,-[1:1]
134-
1 | import 'server-only'
135-
: ^^^^^^^^^^^^^^^^^^^^
136-
2 |
137-
3 | export default function Page() {
138-
4 | return 'hello world'
139-
\`----
140-
141-
Import trace for requested module:"
142-
`)
172+
"./components/Comp.js
173+
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-
174+
| application/rendering/server-components
175+
|
176+
|
177+
,-[1:1]
178+
1 | import 'server-only'
179+
: ^^^^^^^^^^^^^^^^^^^^
180+
2 |
181+
3 | export default function Page() {
182+
4 | return 'hello world'
183+
\`----
184+
185+
Import trace for requested module:"
186+
`)
143187
}
144188
})
145189

@@ -176,27 +220,48 @@ 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(
182247
next.normalizeTestDirContent(await session.getRedboxSource()),
183248
'Import trace for requested module:'
184249
)
185250
).toMatchInlineSnapshot(`
186-
"./components/Comp.js
187-
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-
188-
| application/rendering/server-components
189-
|
190-
|
191-
,-[1:1]
192-
1 | import { after } from 'next/server'
193-
: ^^^^^
194-
2 |
195-
3 | export default function Page() {
196-
4 | return 'hello world'
197-
\`----
198-
199-
Import trace for requested module:"
251+
"./components/Comp.js
252+
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-
253+
| application/rendering/server-components
254+
|
255+
|
256+
,-[1:1]
257+
1 | import { after } from 'next/server'
258+
: ^^^^^
259+
2 |
260+
3 | export default function Page() {
261+
4 | return 'hello world'
262+
\`----
263+
264+
Import trace for requested module:"
200265
`)
201266
}
202267
})
@@ -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)