mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
## 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>
30 lines
887 B
TypeScript
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);
|
|
});
|