Files
bun.sh/test/regression/issue/ENG-24434.test.ts
robobun e624f1e571 fix(jest): handle null SourceOrigin in jest.mock() to prevent crash (#25281)
## Summary
- Added null check for `sourceOrigin` before accessing its URL in
`jest.mock()`
- When `callerSourceOrigin()` returns null (e.g., when called with
invalid arguments), the code now safely returns early instead of
crashing

## Test plan
- [x] Added regression test `test/regression/issue/ENG-24434.test.ts`
- [x] `bun bd test test/regression/issue/ENG-24434.test.ts` passes

Fixes ENG-24434

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2025-12-01 11:54:03 -08:00

30 lines
887 B
TypeScript

import { expect, test } from "bun:test";
// Regression test for ENG-24434
// jest.mock() with invalid arguments should throw TypeError, not crash
test("jest.mock() with non-string first argument should throw TypeError", () => {
const jestObj = Bun.jest(import.meta.path).jest;
// Passing the jest object itself as the first argument should throw
// a TypeError, not crash with stack-buffer-overflow
expect(() => {
jestObj.mock(jestObj);
}).toThrow(TypeError);
});
test("jest.mock() with object as first argument should throw TypeError", () => {
const jestObj = Bun.jest(import.meta.path).jest;
expect(() => {
jestObj.mock({});
}).toThrow(TypeError);
});
test("jest.mock() with missing callback should throw TypeError", () => {
const jestObj = Bun.jest(import.meta.path).jest;
expect(() => {
jestObj.mock("some-module");
}).toThrow(TypeError);
});