-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Labels
Description
Describe the bug
Starting Vitest 4.0.7+ it works well with the Bun runtime. Tried out with different configurations and setup and that works fine.
Except the Module Mocking, which always end up loading the actual version of the module instead of mocked.
Reproduction
// my_modules/sum.js
export function sum (a, b) {
return a + b;
}// sum.test.js
import {describe, it, vi, expect} from "vitest";
import {sum} from "./my_modules/sum.js";
vi.mock("./my_modules/sum.js")
describe("sum", () => {
it("add up", () => {
sum.mockReturnVaue(10);
expect(sum(9, 8)).toEqual(10);
});
});When executed in NodeJS it works fine and sum import would be a mock. But when executed in Bun the sum returns is actual function not mock.
System Info
System:
OS: macOS 26.1
CPU: (11) arm64 Apple M3 Pro
Memory: 212.30 MB / 18.00 GB
Shell: 5.9 - /opt/homebrew/bin/zsh
Binaries:
Node: 22.13.0 - /Users/nazar/.asdf/installs/nodejs/22.13.0/bin/node
Yarn: 1.22.22 - /Users/nazar/.asdf/installs/nodejs/22.13.0/bin/yarn
npm: 10.9.2 - /Users/nazar/.asdf/plugins/nodejs/shims/npm
pnpm: 10.13.1 - /Users/nazar/.bun/bin/pnpm
bun: 1.3.1 - /Users/nazar/.asdf/shims/bun
Deno: 2.2.8 - /Users/nazar/.asdf/shims/deno
Browsers:
Brave Browser: 142.1.84.135
Edge: 140.0.3485.54
Safari: 26.1Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.