@exodus/test

中文文档
1.0.0-rc.117发布于 2026/10/21MITTypeScriptESM + CJS零依赖近 30 天下载 2.4万

A test suite runner

原始使用文档
文档目录12 节
  1. Features
  2. Getting started
  3. Using with node:test tests
  4. Migrating from Jest
  5. Migrating from tape
  6. Engines
  7. Options
  8. Reporter samples
  9. CLI
  10. GitHub Actions
  11. Module mocking in ESM
  12. License

@exodus/test

A runner for node:test, jest, and tape test suites on top of node:test (and any runtime).


It can run your existing tests on all runtimes and also browsers, with snapshots and module mocks:

Node.js Deno Bun Electron workerd
Chrome WebKit Firefox Brave Microsoft Edge Servo
Hermes V8 JavaScriptCore SpiderMonkey
QuickJS XS GraalJS Boa Nova Escargot engine262

Compatible with tests written in:

node:test Jest tape

See documentation.

Features

  • Zero learning curve: runs your existing tests
  • Runs anywhere (including Hermes, the React Native JavaScript engine)
  • Native ESM, including in Jest tests
  • Esbuild on the fly for old faux-ESM interop (enable via --esbuild)
  • TypeScript support
  • Use snapshots to cross-compare between runtimes, browsers and barebones (including Hermes)
  • Testsuite-agnostic — can run any file as long as it sets exit code based on test results
  • Built-in Jest compatibility (with --jest), including jest.* global
    • Up to ~10x faster depending on the original setup
    • Actual expect module, also jest-extended and jest-when just work on top
    • Snapshots, including snapshot matchers
    • Function and timer mocks
    • test.concurrent
    • Module mocks, including for ESM modules (already loaded ESM modules can be mocked only on node:test)
    • Loads Jest configuration
  • Built-in network record/replay for offline tests, mocking fetch and WebSocket sessions
  • --drop-network support for guaranteed offline testing
  • Native code coverage via v8 (Node.js or c8), with istanbul reporters
  • GitHub reporter (auto-enabled by default)
  • JSDOM env support
  • Hanging tests error by default (unlike jest)
  • Babel support, picks up your Babel config (enable via --babel)
  • Unlike bun:test, it runs test files in isolated contexts on Bun.
    Without this, Bun leaks globals / side effects between test files (ref), and has incompatible test() lifecycle / order

Getting started

First install with npm install --save-dev @exodus/test (or with your favorite package manager)

Then, add this to package.json scripts (or see engines example):

  "test": "exodus-test"

That's it. It works zero-config.

See Options to change defaults, e.g. to enable Jest globals with --jest.

To use Engines on CI, see e.g. GitHub CI config of @exodus/bytes.

Using with node:test tests

You don't need to change the tests or any extra configuration on top of Getting started.

It just works out of the box, and on Node.js native node:test is used under the hood.

Using this script is similar to node --test:

  "test": "exodus-test"

But, unlike bare node --test it supports engines and the GitHub CI reporter.

Migrating from Jest

Use this in package.json scripts:

  "test": "exodus-test --jest"

If that doesn't work (e.g. some deps are faux-ESM), add --esbuild to transpile those:

  "test": "exodus-test --jest --esbuild"

To adjust module mocks for native ESM support, see Module mocking in ESM.

Some complex setups with React Native don't work yet.

Migrating from tape

Use this in package.json scripts:

  "test": "exodus-test"

Great! Now your tape tests run on top of node:test, and are also runnable in browsers / barebone engines.

[!TIP] You can optionally replace tape imports with @exodus/test/tape to be able to be individually run them with just node ./path-to-file.js:

import test from '@exodus/test/tape' // ESM
const test = require('@exodus/test/tape') // CJS

Engines

Use --engine (or EXODUS_TEST_ENGINE=) to specify one of:

  • node:test — the default one, runs on top of modern Node.js test runner API
  • node:pure — implementation in pure JS, runs on Node.js
  • node:bundle — same as node:pure, but bundles everything into a single file before launching
  • Other runtimes:
    • deno:pure — Deno (requires Deno v2.4.0 or later, expects deno to be available)
    • deno:bundle — Deno (v1 or v2, whichever deno is)
    • deno:test — incomplete, lacks --jest support due to missing afterEach / beforeEach in Deno
    • bun:pure / bun:bundle — Bun, expects bun to be available
    • electron-as-node:test / electron-as-node:pure / electron-as-node:bundle
      Same as node:*, but uses electron binary.
      The usecase is mostly to test on BoringSSL instead of OpenSSL.
    • electron:bundle — run tests in Electron BrowserWindow without Node.js integration.
    • workerd:bundle — Cloudflare Workers runtime (workerd), expects workerd package to be installed
  • Browsers:
    • Playwright builds (install Playwright-built engines with exodus-test --playwright install)
      • chromium:playwright — Playwright-built Chromium
      • firefox:playwright — Playwright-built Firefox
      • webkit:playwright — Playwright-built WebKit, close to Safari
      • chrome:playwright — Chrome (system-installed)
      • msedge:playwright — Microsoft Edge (system-installed)
    • Puppeteer (system-provided or upstream builds)
      • chrome:puppeteer — Chrome
      • firefox:puppeteer — Firefox
      • brave:puppeteer — Brave
      • msedge:puppeteer — Microsoft Edge
    • Bundle
      • servo:bundle — Servo (expects it to be installed in the system)
  • Barebone engines (system-provided or installed with npx jsvu / npx esvu):
    • v8:bundle — v8 CLI (Chrome/Blink/Node.js JavaScript engine)
    • jsc:bundle — JavaScriptCore (Safari/WebKit JavaScript engine)
    • hermes:bundle — Hermes (React Native JavaScript engine)
    • spidermonkey:bundle — SpiderMonkey (Firefox/Gecko JavaScript engine)
    • quickjs:bundle — QuickJS
    • xs:bundle — Moddable XS
    • graaljs:bundle — GraalJS
    • escargot:bundle — Escargot
    • boa:bundle — Boa
    • nova:bundle — Nova (note that Nova itself is a Work In Progress)
    • engine262:bundle - engine262, the per-spec implementation of ECMA-262 (install with esvu)

Options

  • --jest — register jest test helpers as global variables, also load jest.config.* configuration options

  • --esbuild — use esbuild loader, also enables Typescript support on old Node.js

  • --typescript — enable Typescript type stripping (only needed on older Node.js versions which don't have it natively)

  • --babel — use babel loader (slower than --esbuild, makes sense if you have a special config)

  • --coverage — enable coverage, prints coverage output (varies by coverage engine)

  • --coverage-engine c8 — use c8 coverage engine (default), also generates ./coverage/ dirs

  • --coverage-engine node — use Node.js builtint coverage engine

  • --watch — operate in watch mode and re-run tests on file changes

  • --only — only run the tests marked with test.only

  • --passWithNoTests — do not error when no test files were found

  • --write-snapshots — write snapshots instead of verifying them (has --test-update-snapshots alias)

  • --test-force-exit — force exit after tests are done

  • --engine — specify one of Engines to run on

Reporter samples

CLI

Uses colors when output supports them, e.g. in terminal.

# tests/jest/expect.mock.test.js
✔ PASS drinkAll > drinks something lemon-flavoured (1.300417ms)
✔ PASS drinkAll > does not drink something octopus-flavoured (0.191791ms)
✔ PASS drinkAll (1.842959ms)
✔ PASS drinkEach > drinkEach drinks each drink (0.360625ms)
✔ PASS drinkEach (0.463416ms)
✔ PASS toHaveBeenCalledWith > registration applies correctly to orange La Croix (0.53325ms)
✔ PASS toHaveBeenCalledWith (0.564166ms)
✔ PASS toHaveBeenLastCalledWith > applying to all flavors does mango last (0.380375ms)
✔ PASS toHaveBeenLastCalledWith (0.473417ms)
# tests/jest/fn.invocationCallOrder.test.js
✔ PASS mock.invocationCallOrder (4.221042ms)

GitHub Actions

Collapses test results per-file, like this:

✅ tests/jest/lifecycle.test.js
  ✔ PASS A > B > C (3.26166ms)
  ✔ PASS A > B > D (1.699463ms)
  ✔ PASS A > B (6.72719ms)
  ✔ PASS A > E > F (1.117997ms)
  ✔ PASS A > E > G > H (1.330904ms)
  ✔ PASS A > E > G (1.94971ms)
  ✔ PASS A > E (3.821825ms)
  ✔ PASS A > I (0.533096ms)
  ✔ PASS A (13.887889ms)
  ✔ PASS J (0.373187ms)
  ✔ PASS K > L (0.659852ms)
  ✔ PASS K (1.143195ms)
 
✅ tests/jest/timers.async.test.js
  ✔ PASS advanceTimersByTime() does not let microtasks to pass (5.326604ms)
  ✔ PASS advanceTimersByTime() does not let microtasks to pass even with await (1.336064ms)
  ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass (6.99526ms)
  ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass, chained (10.131664ms)
  ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass, longer chained (8.635472ms)
  ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass, async chain (56.937983ms)
 

See live output in CI

Module mocking in ESM

Module mocks in ESM is a common source of confusion, as Jest in most old setups does not run real ESM, and instead uses Babel to transform ESM into CJS, and then hoists mocks on top of require() calls.

That hoisting is not possible in ESM world, as static import statements are always resolved before any other code.

Also see Jest documentation on that.

To port code from CJS or Babel, e.g. the following approach with dynamic imports can be used:

jest.doMock('./hogwarts.js', () => ({
  __esModule: true,
  default: jest.fn(),
}))

const { default: getEntryQualification } = await import('./hogwarts.js')
const { qualifiesForHogwarts } = await import('./wizard.js') // module importing ./hogwarts.js

test('qualifies for Hogwarts', () => {
  // doSomething is a mock function
  getEntryQualification.mockReturnValue(['lumos'])

  expect(qualifiesForHogwarts('potter')).toBe(false)
  getEntryQualification.mockReturnValue([])
  expect(qualifiesForHogwarts('potter')).toBe(true)
})

Note that all modules that transitively import hogwarts.js will have to be imported after the mock is defined.

License

MIT

版本与发布记录

@exodus/test 共发布 118 个版本,首次发布于 2024/07/06;过去 12 个月发布了 10 个版本。

版本发布日期距今
1.0.0-rc.117latest2026/10/2123 天前
1.0.0-rc.1162026/02/178 个月前
1.0.0-rc.1152026/02/109 个月前
1.0.0-rc.1142026/02/089 个月前
1.0.0-rc.1132026/02/079 个月前
1.0.0-rc.1122026/02/069 个月前

关于 @exodus/test 的常见问题

@exodus/test 是什么?

A test suite runner

如何安装 @exodus/test?

在项目目录运行 npm install @exodus/test,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 exodus-test,可以用 npx exodus-test 直接运行。

@exodus/test 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@exodus/test 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@exodus/test 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.19.0 || ^22.12.0 || >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@exodus/test 可以商用吗?

@exodus/test 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/test 的下载量有多少?

根据 npm 官方下载统计,@exodus/test 在 2026/10/14 – 2026/11/12 这 30 天内被下载 23,912 次,日均约 797 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/test 还在维护吗?

最新版本 1.0.0-rc.117 发布于 2026/10/21(23 天前);至今共发布 118 个版本,其中过去 12 个月发布了 10 个;首次发布于 2024/07/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。