Skip to content

Commit 29c27e8

Browse files
authored
[test] Fix flaky error-recovery test (#76789)
Fixes https://github.com/vercel/next.js/actions/runs/13651039022/job/38159568577?pr=76787#step:33:639 Sometimes we didn't get to assert in time before more errors come in. Now the test ensures that each error is intentional.
1 parent df77469 commit 29c27e8

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

Diff for: test/development/acceptance-app/error-recovery.test.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -534,28 +534,31 @@ describe('Error recovery app', () => {
534534
outdent`
535535
import * as React from 'react';
536536
let i = 0
537-
setInterval(() => {
538-
i++
539-
throw Error('no ' + i)
540-
}, 1000)
537+
window.triggerError = () => {
538+
// TODO(veil): sync thrown errors do not trigger Redbox.
539+
setTimeout(() => {
540+
i++
541+
throw Error('no ' + i)
542+
}, 0)
543+
}
541544
export default function FunctionNamed() {
542545
return <div />
543546
}
544547
`
545548
)
546549

547-
await new Promise((resolve) => setTimeout(resolve, 1000))
550+
await browser.eval('window.triggerError()')
548551
await expect(browser).toDisplayCollapsedRedbox(`
549552
{
550553
"count": 1,
551554
"description": "Error: no 1",
552555
"environmentLabel": null,
553556
"label": "Unhandled Runtime Error",
554-
"source": "index.js (5:9) @ eval
555-
> 5 | throw Error('no ' + i)
556-
| ^",
557+
"source": "index.js (7:11) @ eval
558+
> 7 | throw Error('no ' + i)
559+
| ^",
557560
"stack": [
558-
"eval index.js (5:9)",
561+
"eval index.js (7:11)",
559562
],
560563
}
561564
`)
@@ -566,10 +569,13 @@ describe('Error recovery app', () => {
566569
outdent`
567570
import * as React from 'react';
568571
let i = 0
569-
setInterval(() => {
570-
i++
571-
throw Error('no ' + i)
572-
}, 1000)
572+
window.triggerError = () => {
573+
// TODO(veil): sync thrown errors do not trigger Redbox.
574+
setTimeout(() => {
575+
i++
576+
throw Error('no ' + i)
577+
}, 0)
578+
}
573579
export default function FunctionNamed() {
574580
`
575581
)
@@ -598,13 +604,10 @@ describe('Error recovery app', () => {
598604
"label": "Build Error",
599605
"source": "./index.js
600606
Error: x Expected '}', got '<eof>'
601-
,-[7:1]
602-
4 | i++
603-
5 | throw Error('no ' + i)
604-
6 | }, 1000)
605-
7 | export default function FunctionNamed() {
606-
: ^
607-
\`----
607+
,-[10:1]
608+
10 | export default function FunctionNamed() {
609+
: ^
610+
\`----
608611
Caused by:
609612
Syntax Error
610613
Import trace for requested module:
@@ -616,7 +619,7 @@ describe('Error recovery app', () => {
616619
}
617620

618621
// Test that runtime error does not take over:
619-
await new Promise((resolve) => setTimeout(resolve, 2000))
622+
await browser.eval('window.triggerError()')
620623
if (isTurbopack) {
621624
await expect(browser).toDisplayRedbox(`
622625
{
@@ -640,13 +643,10 @@ describe('Error recovery app', () => {
640643
"label": "Build Error",
641644
"source": "./index.js
642645
Error: x Expected '}', got '<eof>'
643-
,-[7:1]
644-
4 | i++
645-
5 | throw Error('no ' + i)
646-
6 | }, 1000)
647-
7 | export default function FunctionNamed() {
648-
: ^
649-
\`----
646+
,-[10:1]
647+
10 | export default function FunctionNamed() {
648+
: ^
649+
\`----
650650
Caused by:
651651
Syntax Error
652652
Import trace for requested module:

0 commit comments

Comments
 (0)