Unverified Commit 29c27e83 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[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.
parent df774690
...@@ -534,28 +534,31 @@ describe('Error recovery app', () => { ...@@ -534,28 +534,31 @@ describe('Error recovery app', () => {
outdent` outdent`
import * as React from 'react'; import * as React from 'react';
let i = 0 let i = 0
setInterval(() => { window.triggerError = () => {
i++ // TODO(veil): sync thrown errors do not trigger Redbox.
throw Error('no ' + i) setTimeout(() => {
}, 1000) i++
throw Error('no ' + i)
}, 0)
}
export default function FunctionNamed() { export default function FunctionNamed() {
return <div /> return <div />
} }
` `
) )
await new Promise((resolve) => setTimeout(resolve, 1000)) await browser.eval('window.triggerError()')
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
"count": 1, "count": 1,
"description": "Error: no 1", "description": "Error: no 1",
"environmentLabel": null, "environmentLabel": null,
"label": "Unhandled Runtime Error", "label": "Unhandled Runtime Error",
"source": "index.js (5:9) @ eval "source": "index.js (7:11) @ eval
> 5 | throw Error('no ' + i) > 7 | throw Error('no ' + i)
| ^", | ^",
"stack": [ "stack": [
"eval index.js (5:9)", "eval index.js (7:11)",
], ],
} }
`) `)
...@@ -566,10 +569,13 @@ describe('Error recovery app', () => { ...@@ -566,10 +569,13 @@ describe('Error recovery app', () => {
outdent` outdent`
import * as React from 'react'; import * as React from 'react';
let i = 0 let i = 0
setInterval(() => { window.triggerError = () => {
i++ // TODO(veil): sync thrown errors do not trigger Redbox.
throw Error('no ' + i) setTimeout(() => {
}, 1000) i++
throw Error('no ' + i)
}, 0)
}
export default function FunctionNamed() { export default function FunctionNamed() {
` `
) )
...@@ -598,13 +604,10 @@ describe('Error recovery app', () => { ...@@ -598,13 +604,10 @@ describe('Error recovery app', () => {
"label": "Build Error", "label": "Build Error",
"source": "./index.js "source": "./index.js
Error: x Expected '}', got '<eof>' Error: x Expected '}', got '<eof>'
,-[7:1] ,-[10:1]
4 | i++ 10 | export default function FunctionNamed() {
5 | throw Error('no ' + i) : ^
6 | }, 1000) \`----
7 | export default function FunctionNamed() {
: ^
\`----
Caused by: Caused by:
Syntax Error Syntax Error
Import trace for requested module: Import trace for requested module:
...@@ -616,7 +619,7 @@ describe('Error recovery app', () => { ...@@ -616,7 +619,7 @@ describe('Error recovery app', () => {
} }
// Test that runtime error does not take over: // Test that runtime error does not take over:
await new Promise((resolve) => setTimeout(resolve, 2000)) await browser.eval('window.triggerError()')
if (isTurbopack) { if (isTurbopack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
...@@ -640,13 +643,10 @@ describe('Error recovery app', () => { ...@@ -640,13 +643,10 @@ describe('Error recovery app', () => {
"label": "Build Error", "label": "Build Error",
"source": "./index.js "source": "./index.js
Error: x Expected '}', got '<eof>' Error: x Expected '}', got '<eof>'
,-[7:1] ,-[10:1]
4 | i++ 10 | export default function FunctionNamed() {
5 | throw Error('no ' + i) : ^
6 | }, 1000) \`----
7 | export default function FunctionNamed() {
: ^
\`----
Caused by: Caused by:
Syntax Error Syntax Error
Import trace for requested module: Import trace for requested module:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment