Skip to content

Commit

Permalink
Turbopack HMR: use own snapshot in error-recovery
Browse files Browse the repository at this point in the history
This records dedicated snapshots for Turbopack for the remaining tests in `test/development/acceptance/error-recovery.test.ts`. The only remaining difference was the lack of Import trace information.

Test Plan: `TURBOPACK=1 pnpm test-dev test/development/acceptance/error-recovery.test.ts`
  • Loading branch information
wbinnssmith committed Mar 18, 2024
1 parent 049d127 commit 49a9f77
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 40 deletions.
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

0 comments on commit 49a9f77

Please sign in to comment.