Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack HMR: use own snapshot in error-recovery #63417

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ exports[`ReactRefreshLogBox default syntax > runtime error 1`] = `
7 | export default function FunctionNamed() {
8 | return <div />"
`;

exports[`ReactRefreshLogBox turbo syntax > runtime error 1`] = `
"index.js (5:9) @ eval

3 | setInterval(() => {
4 | i++
> 5 | throw Error('no ' + i)
| ^
6 | }, 1000)
7 | export default function FunctionNamed() {
8 | return <div />"
`;
111 changes: 71 additions & 40 deletions test/development/acceptance/error-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,50 +434,81 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {

await new Promise((resolve) => setTimeout(resolve, 1000))
expect(await session.hasRedbox()).toBe(true)
expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(`
"./index.js
Error:
x Expected '}', got '<eof>'
,-[TEST_DIR/index.js:4:1]
4 | i++
5 | throw Error('no ' + i)
6 | }, 1000)
7 | export default function FunctionNamed() {
: ^
\`----

Caused by:
Syntax Error

Import trace for requested module:
./index.js
./pages/index.js"
`)
let redboxSource = next.normalizeTestDirContent(
await session.getRedboxSource()
)

if (isTurbopack) {
// TODO: Remove this branching once import traces are implemented in Turbopack
expect(redboxSource).toMatchInlineSnapshot(`
"./index.js:7:41
Parsing ecmascript source code failed
5 | throw Error('no ' + i)
6 | }, 1000)
> 7 | export default function FunctionNamed() {
| ^

Expected '}', got '<eof>'"
`)
} else {
expect(redboxSource).toMatchInlineSnapshot(`
"./index.js
Error:
x Expected '}', got '<eof>'
,-[TEST_DIR/index.js:4:1]
4 | i++
5 | throw Error('no ' + i)
6 | }, 1000)
7 | export default function FunctionNamed() {
: ^
\`----

Caused by:
Syntax Error

Import trace for requested module:
./index.js
./pages/index.js"
`)
}

// Test that runtime error does not take over:
await new Promise((resolve) => setTimeout(resolve, 2000))
expect(await session.hasRedbox()).toBe(true)
expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(`
"./index.js
Error:
x Expected '}', got '<eof>'
,-[TEST_DIR/index.js:4:1]
4 | i++
5 | throw Error('no ' + i)
6 | }, 1000)
7 | export default function FunctionNamed() {
: ^
\`----

Caused by:
Syntax Error

Import trace for requested module:
./index.js
./pages/index.js"
`)
redboxSource = next.normalizeTestDirContent(await session.getRedboxSource())
if (isTurbopack) {
// TODO: Remove this branching once import traces are implemented in Turbopack
expect(redboxSource).toMatchInlineSnapshot(`
"./index.js:7:41
Parsing ecmascript source code failed
5 | throw Error('no ' + i)
6 | }, 1000)
> 7 | export default function FunctionNamed() {
| ^

Expected '}', got '<eof>'"
`)
} else {
expect(redboxSource).toMatchInlineSnapshot(`
"./index.js
Error:
x Expected '}', got '<eof>'
,-[TEST_DIR/index.js:4:1]
4 | i++
5 | throw Error('no ' + i)
6 | }, 1000)
7 | export default function FunctionNamed() {
: ^
\`----

Caused by:
Syntax Error

Import trace for requested module:
./index.js
./pages/index.js"
`)
}

await cleanup()
})
Expand Down
Loading