Skip to main content

Module node_test

Module node_test 

Source
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:

  1. Install-order freeze: the previous source resolved __bun_test_module once at module-eval time. node_test::install runs BEFORE bun_test::install_bun_test in globals.rs, so the resolution always saw undefined and froze an inert test: function(){} stub into the builtin cache — even under bao test, node:test files registered nothing and reported 0/0. All bridging is now resolved lazily at call time.
  2. 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 unless process.argv[1] === 'test' (the bao test subcommand).

§Architecture

Follows the same JS IIFE pattern as node_stream.rs / node_vm.rs:

  • TEST_SOURCE const holds the JS source
  • install() evaluates the IIFE, extracts the returned object, and registers it via cache_builtin(cx, "test", ...) (require() strips the node: 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

Functions§

install