Skip to content

Commit f5e2dcc

Browse files
authored
Update use-cache-unknown-cache-kind.test.ts snapshot for alternate bundler (#76682)
This adds a snapshot for rspack to this test. It also mentions rspack instead of webpack when failing with build errors. Test Plan: `pnpm test-start-rspack test/e2e/app-dir/use-cache-unknown-cache-kind/use-cache-unknown-cache-kind.test.ts`
1 parent e45411e commit f5e2dcc

File tree

4 files changed

+88
-40
lines changed

4 files changed

+88
-40
lines changed

packages/next/errors.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -658,5 +658,6 @@
658658
"657": "revalidate must be a number for image-cache",
659659
"658": "Pass `Infinity` instead of `false` if you want to cache on the server forever without checking with the origin.",
660660
"659": "SSG should not return an image cache value",
661-
"660": "Rspack support is only available in Next.js canary."
661+
"660": "Rspack support is only available in Next.js canary.",
662+
"661": "Build failed because of %s errors"
662663
}

packages/next/src/build/webpack-build/impl.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ export async function webpackBuildImpl(
333333
err.code = 'INVALID_RESOLVE_ALIAS'
334334
throw err
335335
}
336-
const err = new Error('Build failed because of webpack errors') as NextError
336+
const err = new Error(
337+
`Build failed because of ${process.env.NEXT_RSPACK ? 'rspack' : 'webpack'} errors`
338+
) as NextError
337339
err.code = 'WEBPACK_ERRORS'
338340
throw err
339341
} else {

test/e2e/app-dir/use-cache-unknown-cache-kind/use-cache-unknown-cache-kind.test.ts

+73-29
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
import stripAnsi from 'strip-ansi'
1111
import { createSandbox } from 'development-sandbox'
1212

13+
const isRspack = process.env.NEXT_RSPACK
14+
1315
const nextConfigWithCacheHandler: NextConfig = {
1416
experimental: {
1517
dynamicIO: true,
@@ -57,26 +59,49 @@ describe('use-cache-unknown-cache-kind', () => {
5759
at <unknown> (./app/page.tsx:1:1)
5860
"
5961
`)
62+
} else if (isRspack) {
63+
expect(buildOutput).toMatchInlineSnapshot(`
64+
"
65+
./app/page.tsx
66+
× Module build failed:
67+
╰─▶ × Error: x Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config.
68+
│ |
69+
│ ,-[1:1]
70+
│ 1 | 'use cache: custom'
71+
│ : ^^^^^^^^^^^^^^^^^^^
72+
│ 2 |
73+
│ 3 | export default async function Page() {
74+
│ 4 | return <p>hello world</p>
75+
│ \`----
76+
77+
78+
Import trace for requested module:
79+
./app/page.tsx
80+
81+
82+
> Build failed because of rspack errors
83+
"
84+
`)
6085
} else {
6186
expect(buildOutput).toMatchInlineSnapshot(`
62-
"
63-
./app/page.tsx
64-
Error: x Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config.
65-
|
66-
,-[1:1]
67-
1 | 'use cache: custom'
68-
: ^^^^^^^^^^^^^^^^^^^
69-
2 |
70-
3 | export default async function Page() {
71-
4 | return <p>hello world</p>
72-
\`----
73-
74-
Import trace for requested module:
75-
./app/page.tsx
76-
77-
78-
> Build failed because of webpack errors
79-
"
87+
"
88+
./app/page.tsx
89+
Error: x Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config.
90+
|
91+
,-[1:1]
92+
1 | 'use cache: custom'
93+
: ^^^^^^^^^^^^^^^^^^^
94+
2 |
95+
3 | export default async function Page() {
96+
4 | return <p>hello world</p>
97+
\`----
98+
99+
Import trace for requested module:
100+
./app/page.tsx
101+
102+
103+
> Build failed because of webpack errors
104+
"
80105
`)
81106
}
82107
})
@@ -104,6 +129,10 @@ describe('use-cache-unknown-cache-kind', () => {
104129
expect(errorDescription).toMatchInlineSnapshot(
105130
`"Ecmascript file had an error"`
106131
)
132+
} else if (isRspack) {
133+
expect(errorDescription).toMatchInlineSnapshot(
134+
`" × Module build failed:"`
135+
)
107136
} else {
108137
expect(errorDescription).toMatchInlineSnapshot(
109138
`"Error: x Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config."`
@@ -122,19 +151,34 @@ describe('use-cache-unknown-cache-kind', () => {
122151
123152
Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config."
124153
`)
154+
} else if (isRspack) {
155+
expect(errorSource).toMatchInlineSnapshot(`
156+
"./app/page.tsx
157+
× Module build failed:
158+
╰─▶ × Error: x Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config.
159+
│ |
160+
│ ,-[1:1]
161+
│ 1 | 'use cache: custom'
162+
│ : ^^^^^^^^^^^^^^^^^^^
163+
│ 2 |
164+
│ 3 | export default async function Page() {
165+
│ 4 | return <p>hello world</p>
166+
│ \`----
167+
│"
168+
`)
125169
} else {
126170
expect(errorSource).toMatchInlineSnapshot(`
127-
"./app/page.tsx
128-
Error: x Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config.
129-
|
130-
,-[1:1]
131-
1 | 'use cache: custom'
132-
: ^^^^^^^^^^^^^^^^^^^
133-
2 |
134-
3 | export default async function Page() {
135-
4 | return <p>hello world</p>
136-
\`----"
137-
`)
171+
"./app/page.tsx
172+
Error: x Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config.
173+
|
174+
,-[1:1]
175+
1 | 'use cache: custom'
176+
: ^^^^^^^^^^^^^^^^^^^
177+
2 |
178+
3 | export default async function Page() {
179+
4 | return <p>hello world</p>
180+
\`----"
181+
`)
138182
}
139183
})
140184

test/integration/css-customization/test/index.test.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { nextBuild } from 'next-test-utils'
66
import escapeStringRegexp from 'escape-string-regexp'
77

88
const fixturesDir = join(__dirname, '../..', 'css-fixtures')
9+
const BUILD_FAILURE_RE = /Build failed because of (webpack|rspack) errors/
910

1011
// Test checks webpack loaders and plugins.
1112
;(process.env.TURBOPACK ? describe.skip : describe)('CSS Customization', () => {
@@ -266,7 +267,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
266267
expect(stderr).toMatch(
267268
/A PostCSS Plugin was passed as an array but did not provide its configuration \('postcss-trolling'\)/
268269
)
269-
expect(stderr).toMatch(/Build failed because of webpack errors/)
270+
expect(stderr).toMatch(BUILD_FAILURE_RE)
270271
})
271272
})
272273

@@ -286,7 +287,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
286287
expect(stderr).toMatch(
287288
/To disable 'postcss-trolling', pass false, otherwise, pass true or a configuration object./
288289
)
289-
expect(stderr).toMatch(/Build failed because of webpack errors/)
290+
expect(stderr).toMatch(BUILD_FAILURE_RE)
290291
})
291292
})
292293

@@ -303,7 +304,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
303304
expect(stderr).toMatch(
304305
/A PostCSS Plugin must be provided as a string. Instead, we got: '5'/
305306
)
306-
expect(stderr).toMatch(/Build failed because of webpack errors/)
307+
expect(stderr).toMatch(BUILD_FAILURE_RE)
307308
})
308309
})
309310

@@ -318,7 +319,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
318319
const { stderr } = await nextBuild(appDir, [], { stderr: true })
319320

320321
expect(stderr).toMatch(/An unknown PostCSS plugin was provided \(5\)/)
321-
expect(stderr).toMatch(/Build failed because of webpack errors/)
322+
expect(stderr).toMatch(BUILD_FAILURE_RE)
322323
})
323324
})
324325

@@ -335,7 +336,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
335336
expect(stderr).toMatch(
336337
/Your custom PostCSS configuration must export a `plugins` key./
337338
)
338-
expect(stderr).toMatch(/Build failed because of webpack errors/)
339+
expect(stderr).toMatch(BUILD_FAILURE_RE)
339340
})
340341
})
341342

@@ -352,7 +353,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
352353
expect(stderr).toMatch(
353354
/Your custom PostCSS configuration must export a `plugins` key./
354355
)
355-
expect(stderr).toMatch(/Build failed because of webpack errors/)
356+
expect(stderr).toMatch(BUILD_FAILURE_RE)
356357
})
357358
})
358359

@@ -369,7 +370,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
369370
expect(stderr).toMatch(
370371
/A PostCSS Plugin was passed as an array but did not provide its configuration \('postcss-trolling'\)/
371372
)
372-
expect(stderr).toMatch(/Build failed because of webpack errors/)
373+
expect(stderr).toMatch(BUILD_FAILURE_RE)
373374
})
374375
})
375376

@@ -386,7 +387,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
386387
expect(stderr).toMatch(
387388
/A PostCSS Plugin was passed as a function using require\(\), but it must be provided as a string/
388389
)
389-
expect(stderr).toMatch(/Build failed because of webpack errors/)
390+
expect(stderr).toMatch(BUILD_FAILURE_RE)
390391
})
391392
})
392393

@@ -403,7 +404,7 @@ const fixturesDir = join(__dirname, '../..', 'css-fixtures')
403404
expect(stderr).toMatch(
404405
/Your custom PostCSS configuration may not export a function/
405406
)
406-
expect(stderr).toMatch(/Build failed because of webpack errors/)
407+
expect(stderr).toMatch(BUILD_FAILURE_RE)
407408
})
408409
})
409410
}

0 commit comments

Comments
 (0)