Expand description
node:test module — bridges to the existing globalThis.__bun_test_module
installed by bun_test.rs.
Exposes the Node.js node:test API surface (test(), describe(), it(),
before/after hooks, mock, assert) by delegating to the bun:test
infrastructure on globalThis.__bun_test_module.
§Silent-fake eradication (group D)
Two bugs are closed here:
- Install-order freeze: the previous source resolved
__bun_test_moduleonce at module-eval time.node_test::installruns BEFOREbun_test::install_bun_testinglobals.rs, so the resolution always sawundefinedand froze an inerttest: function(){}stub into the builtin cache — even underbao test, node:test files registered nothing and reported 0/0. All bridging is now resolved lazily at call time. - Plain-run fake pass: only
bao test(cli.rs → run_test_file → run_bun_tests_report) drives registered tests. In any other mode (bao run,-e, library embedding) registration would silently no-op and the user would believe tests passed. test()/describe()/it() and the hooks now refuse with an explicit throw unlessprocess.argv[1] === 'test'(thebao testsubcommand).
§Architecture
Follows the same JS IIFE pattern as node_stream.rs / node_vm.rs:
TEST_SOURCEconst holds the JS sourceinstall()evaluates the IIFE, extracts the returned object, and registers it viacache_builtin(cx, "test", ...)(require() strips thenode:prefix, so the bare key serves both specifiers)
§References
- Bun upstream:
src/js/node/test.ts - Node.js docs: https://nodejs.org/api/test.html