jest-circus

中文文档
30.5.2发布于 2026/09/18MITTypeScriptESM + CJS近 30 天下载 2.1亿
原始使用文档
文档目录3 节
  1. Overview
  2. Installation
  3. Configure

jest-circus

The next-gen test runner for Jest

Overview

Circus is a flux-based test runner for Jest that is fast, maintainable, and simple to extend.

Circus allows you to bind to events via an optional event handler on any custom environment. See the type definitions for more information on the events and state data currently available.

import type {Event, State} from 'jest-circus';
import {TestEnvironment as NodeEnvironment} from 'jest-environment-node';

class MyCustomEnvironment extends NodeEnvironment {
  //...

  async handleTestEvent(event: Event, state: State) {
    if (event.name === 'test_start') {
      // ...
    }
  }
}

Mutating event or state data is currently unsupported and may cause unexpected behavior or break in a future release without warning. New events, event data, and/or state data will not be considered a breaking change and may be added in any minor release.

Note, that jest-circus test runner would pause until a promise returned from handleTestEvent gets fulfilled. However, there are a few events that do not conform to this rule, namely: start_describe_definition, finish_describe_definition, add_hook, add_test or error (for the up-to-date list you can look at SyncEvent type in the types definitions). That is caused by backward compatibility reasons and process.on('unhandledRejection', callback) signature, but that usually should not be a problem for most of the use cases.

Installation

Note: As of Jest 27, jest-circus is the default test runner, so you do not have to install it to use it.

Install jest-circus using yarn:

yarn add --dev jest-circus

Or via npm:

npm install --save-dev jest-circus

Configure

Configure Jest to use jest-circus via the testRunner option:

{
  "testRunner": "jest-circus/runner"
}

Or via CLI:

jest --testRunner='jest-circus/runner'

版本与发布记录

jest-circus 共发布 276 个版本,首次发布于 2017/06/02;过去 12 个月发布了 7 个版本。

版本发布日期距今
30.5.2latest2026/09/181 个月前
30.5.12026/09/012 个月前
30.5.02026/08/282 个月前
30.4.22026/05/095 个月前
30.4.12026/05/086 个月前
30.4.02026/05/086 个月前

其他发布通道:next → 30.0.0-rc.1。

关于 jest-circus 的常见问题

如何安装 jest-circus?

在项目目录运行 npm install jest-circus,或使用 pnpm add / yarn add / bun add。

jest-circus 支持 TypeScript 吗?

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

jest-circus 支持 ESM 还是 CommonJS?

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

jest-circus 需要什么版本的 Node.js?

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

jest-circus 可以商用吗?

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

jest-circus 的下载量有多少?

根据 npm 官方下载统计,jest-circus 在 2026/10/07 – 2026/11/05 这 30 天内被下载 208,428,009 次,日均约 6,947,600 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

jest-circus 还在维护吗?

最新版本 30.5.2 发布于 2026/09/18(1 个月前);至今共发布 276 个版本,其中过去 12 个月发布了 7 个;首次发布于 2017/06/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。