Bun Tests Replace Functions In Re-exported Modules
11 posts since Mar 2024, all from GitHub.
“What version of Bun is running? 1.0.30 What platform is your computer? Linux debian 10 What steps can reproduce the bug? with jest there is not a problem What is the expected behavior? What do you see instead? error: expect(received).not.toBeDefined() Received: null Additional…”
“What version of Bun is running? 1.4.6 canary.1+dac8e3b0f What platform is your computer? macOS arm64 (Darwin 25.5.0) What steps can reproduce the bug? No dependencies: bun test serves the vitest import itself. before all wrapper tostring.test.ts Run bun test ./before all wrapper…”
“What version of Bun is running? 1.4.0 canary.1+b4045c17b What platform is your computer? Darwin 25.5.0 arm64 arm What steps can reproduce the bug? There are gaps in bun's implementation of the vitest and jest implementation that throw errors when running the test suites…”
Several users are encountering issues with Bun's testing environment, specifically when using Jest mocks. The mocks are unexpectedly replacing functions in modules that are re-exported, leading to test failures and unexpected behavior. This problem appears to be related to how Bun handles module loading and mocking in test scenarios.
SOURCES (11)
“What version of Bun is running? 1.4.6 canary.1+dac8e3b0f What platform is your computer? macOS arm64 (Darwin 25.5.0) What steps can reproduce the bug? No dependencies: bun test serves the vitest import itself. before all wrapper tostring.test.ts Run bun test ./before all wrapper tostring.test.ts . What…”
“What version of Bun is running? 1.4.6 canary.1+dac8e3b0f What platform is your computer? macOS arm64 (Darwin 25.5.0) What steps can reproduce the bug? dispatcher.ts store.ts (registers a callback when it loads, like a Flux store) drift.ts ( drift.ts and store.ts import each other) mockHelpers.ts (a shared helper: the real module with some exports replaced) helper.test.ts Run bun test ./helper.test.ts . What is the expected behavior? Both tests pass: store.ts is loaded once and registers once. Je”
“What version of Bun is running? 1.4.6 canary.1+dac8e3b0f What platform is your computer? macOS arm64 (Darwin 25.5.0) What steps can reproduce the bug? No dependencies. A tiny local JSX runtime stands in for React, so the parse error is the only failure. tsconfig.json node modules/tiny jsx/package.json node modules/tiny jsx/jsx runtime.js helper.ts plain.tsx Run bun plain.tsx . The same error happens in bun test with a test file whose only imports are import type (they are erased, so the file has”
“What version of Bun is running? 1.4.6 canary.1+dac8e3b0f What platform is your computer? macOS arm64 (Darwin 25.5.0) What steps can reproduce the bug? eaddrinuse.js Run bun eaddrinuse.js and node eaddrinuse.js . What is the expected behavior? The same error as Node 26.13.0 (macOS): node:net in bun already gives this message ( net.createServer().listen(port) prints listen EADDRINUSE: address already in use :::<port ), so only node:http differs. What do you see instead? Additional information code”
“What version of Bun is running? 1.4.6 canary.1+dac8e3b0f What platform is your computer? macOS arm64 (Darwin 25.5.0) What steps can reproduce the bug? Four files in one directory. lib/greet.ts lib/welcome.ts lib/index.ts single.test.ts Run bun test ./single.test.ts . The same happens with the Jest pattern, when a setup file has loaded the barrel before the test file mocks it: setup.ts barrel.test.ts Run bun test preload ./setup.ts ./barrel.test.ts . What is the expected behavior? Only lib/index”
“What version of Bun is running? 1.4.0 canary.1+b4045c17b What platform is your computer? Darwin 25.5.0 arm64 arm What steps can reproduce the bug? There are gaps in bun's implementation of the vitest and jest implementation that throw errors when running the test suites. Notably, there are gaps with timing related functions. There should be a full gap analysis created and sub issues created for the gaps found in each. What is the expected behavior? tests should pas What do you see instead? failu”
“What version of Bun is running? 1.2.5+013fdddc6 What platform is your computer? x64 What steps can reproduce the bug? Throws Throws does not throw does not throw What is the expected behavior? hi should not evaluate when require('fs') is called What do you see instead? hi is evaluated and throws the error, unless we import/require before the prototype override Additional information Image discovered by: alexcraft 75172 discord”
“What version of Bun is running? 1.2.5 What platform is your computer? Darwin 24.3.0 arm64 arm What steps can reproduce the bug? I'm trying to use bun to run some mocha tests, and we make use of testdouble. When running tests, I get lots of TypeError: object is not a function. (In 'object()', 'object' is undefined) , this is when using the imported thing, eg import { object } from 'testdouble' . If I do import as td from testdouble , and console.log it, on node I get: (correct) but on bun i get:”
What version of Bun is running? 1.1.3+2615dc742 What platform is your computer? Linux 4.4.0 19041 Microsoft x86 64 x86 64 What steps can reproduce the bug? What is the expected behavior? What…
“What version of Bun is running? 1.0.30 What platform is your computer? Linux debian 10 What steps can reproduce the bug? with jest there is not a problem What is the expected behavior? What do you see instead? error: expect(received).not.toBeDefined() Received: null Additional information No response”
“What version of Bun is running? 1.0.30+1424a196f What platform is your computer? Darwin 23.4.0 arm64 arm What steps can reproduce the bug? bun init bun i commander in index.ts: bun build target node index.ts outfile build.js node build.js What is the expected behavior? console.log some stuff What do you see instead? var EventEmitter = import.meta.require("events").EventEmitter; ^ TypeError: (intermediate value).require is not a function Additional information regression, past issues: https://git”
