Skip to content

Commit a270b00

Browse files
authored
[turbopack] Add an execution test for the behavior when a module throws an error (#83451)
Confirms that we don't re-evaluate modules after an error Clearing the require.cache allows us to re-evaluate
1 parent 74c3745 commit a270b00

File tree

2 files changed

+27
-0
lines changed
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/evaluation-errors/basic/input

2 files changed

+27
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
it('module evaluation rethrows but does not re-evaluate', async () => {
2+
expect(globalThis.evalCounter).toBeUndefined()
3+
await assertThrowsThrows()
4+
expect(globalThis.evalCounter).toBe(1)
5+
await assertThrowsThrows()
6+
expect(globalThis.evalCounter).toBe(1)
7+
8+
// We do re-evaluate if the module cache is cleared
9+
require.cache[require.resolve('./throws')] = undefined
10+
await assertThrowsThrows()
11+
expect(globalThis.evalCounter).toBe(2)
12+
await assertThrowsThrows()
13+
expect(globalThis.evalCounter).toBe(2)
14+
})
15+
16+
async function assertThrowsThrows() {
17+
try {
18+
await import('./throws')
19+
} catch (e) {
20+
return e
21+
}
22+
throw new Error('should have thrown')
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
globalThis.evalCounter ??= 0
2+
globalThis.evalCounter++
3+
4+
throw new Error('uh oh')

0 commit comments

Comments
 (0)