Skip to content

Commit 733e4d6

Browse files
authored
test: fix snapshots in failing tests (#79254)
1 parent 88c47c2 commit 733e4d6

File tree

2 files changed

+79
-21
lines changed

2 files changed

+79
-21
lines changed

test/development/acceptance-app/error-recovery.test.ts

+63-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/* eslint-env jest */
22
import { createSandbox } from 'development-sandbox'
33
import { FileRef, nextTestSetup } from 'e2e-utils'
4-
import { check } from 'next-test-utils'
4+
import {
5+
assertHasRedbox,
6+
check,
7+
getRedboxCallStack,
8+
getRedboxDescription,
9+
getRedboxEnvironmentLabel,
10+
getRedboxSource,
11+
} from 'next-test-utils'
512
import path from 'path'
613
import { outdent } from 'outdent'
714

@@ -375,20 +382,55 @@ describe('Error recovery app', () => {
375382
`
376383
)
377384

378-
await expect(browser).toDisplayRedbox(`
379-
{
380-
"description": "oops",
381-
"environmentLabel": "Server",
382-
"label": "Runtime Error",
383-
"source": "child.js (3:9) @ Child
384-
> 3 | throw new Error('oops')
385-
| ^",
386-
"stack": [
387-
"Child child.js (3:9)",
388-
"Page app/server/page.js (3:10)",
389-
],
390-
}
391-
`)
385+
{
386+
// FIXME: `label` is flaking between "Runtime Error" and "Recoverable Error",
387+
// so we have to snapshot the redbox manually we figure out why
388+
389+
// await expect(browser).toDisplayRedbox(`
390+
// {
391+
// "description": "oops",
392+
// "environmentLabel": "Server",
393+
// "label": "Recoverable Error",
394+
// "source": "child.js (3:9) @ Child
395+
// > 3 | throw new Error('oops')
396+
// | ^",
397+
// "stack": [
398+
// "Child child.js (3:9)",
399+
// "Page app/server/page.js (3:10)",
400+
// ],
401+
// }
402+
// `)
403+
404+
await assertHasRedbox(browser)
405+
const redbox = await Promise.all([
406+
getRedboxDescription(browser),
407+
getRedboxEnvironmentLabel(browser),
408+
getRedboxSource(browser),
409+
getRedboxCallStack(browser),
410+
]).then(([description, environmentLabel, source, stack]) => ({
411+
description,
412+
environmentLabel,
413+
source,
414+
stack,
415+
}))
416+
expect(redbox).toMatchInlineSnapshot(`
417+
{
418+
"description": "oops",
419+
"environmentLabel": "Server",
420+
"source": "child.js (3:9) @ Child
421+
422+
1 | // hello
423+
2 | export default function Child() {
424+
> 3 | throw new Error('oops')
425+
| ^
426+
4 | }",
427+
"stack": [
428+
"Child child.js (3:9)",
429+
"Page app/server/page.js (3:10)",
430+
],
431+
}
432+
`)
433+
}
392434

393435
// TODO-APP: re-enable when error recovery doesn't reload the page.
394436
/* const didNotReload = */ await session.patch(
@@ -580,10 +622,10 @@ describe('Error recovery app', () => {
580622
"description": "Parsing ecmascript source code failed",
581623
"environmentLabel": null,
582624
"label": "Build Error",
583-
"source": "./index.js (7:41)
625+
"source": "./index.js (10:41)
584626
Parsing ecmascript source code failed
585-
> 7 | export default function FunctionNamed() {
586-
| ^",
627+
> 10 | export default function FunctionNamed() {
628+
| ^",
587629
"stack": [],
588630
}
589631
`)
@@ -617,10 +659,10 @@ describe('Error recovery app', () => {
617659
"description": "Parsing ecmascript source code failed",
618660
"environmentLabel": null,
619661
"label": "Build Error",
620-
"source": "./index.js (7:41)
662+
"source": "./index.js (10:41)
621663
Parsing ecmascript source code failed
622-
> 7 | export default function FunctionNamed() {
623-
| ^",
664+
> 10 | export default function FunctionNamed() {
665+
| ^",
624666
"stack": [],
625667
}
626668
`)

test/development/app-dir/use-cache-errors/use-cache-errors.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('use-cache-errors', () => {
55
const { next, isTurbopack } = nextTestSetup({
66
files: __dirname,
77
})
8+
const isRspack = Boolean(process.env.NEXT_RSPACK)
89

910
it('should not show a false-positive compiler error about a misplaced "use cache" directive', async () => {
1011
// This is a regression test to ensure that an injected React Refresh
@@ -35,6 +36,21 @@ describe('use-cache-errors', () => {
3536
],
3637
}
3738
`)
39+
} else if (isRspack) {
40+
// TODO: the source is missing and the stack leaks rspack internals
41+
await expect(browser).toDisplayRedbox(`
42+
{
43+
"description": "Attempted to call useStuff() from the server but useStuff is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.",
44+
"environmentLabel": "Cache",
45+
"label": "Runtime Error",
46+
"source": null,
47+
"stack": [
48+
"<FIXME-file-protocol>",
49+
"useCachedStuff rsc:/Cache/webpack-internal:///(action-browser)/app/module-with-use-cache.ts (25:68)",
50+
"Page ./app/page.tsx",
51+
],
52+
}
53+
`)
3854
} else {
3955
await expect(browser).toDisplayRedbox(`
4056
{

0 commit comments

Comments
 (0)