| 1 | [type-definitions]: https://github.com/facebook/jest/blob/main/packages/jest-types/src/Circus.ts
|
|---|
| 2 |
|
|---|
| 3 | <h1 align="center">
|
|---|
| 4 | <img src="https://jestjs.io/img/jest.png" height="150" width="150"/>
|
|---|
| 5 | <img src="https://jestjs.io/img/circus.png" height="150" width="150"/>
|
|---|
| 6 | <p align="center">jest-circus</p>
|
|---|
| 7 | <p align="center">The next-gen test runner for Jest</p>
|
|---|
| 8 | </h1>
|
|---|
| 9 |
|
|---|
| 10 | ## Overview
|
|---|
| 11 |
|
|---|
| 12 | Circus is a flux-based test runner for Jest that is fast, maintainable, and simple to extend.
|
|---|
| 13 |
|
|---|
| 14 | Circus allows you to bind to events via an optional event handler on any [custom environment](https://jestjs.io/docs/configuration#testenvironment-string). See the [type definitions][type-definitions] for more information on the events and state data currently available.
|
|---|
| 15 |
|
|---|
| 16 | ```js
|
|---|
| 17 | import {Event, State} from 'jest-circus';
|
|---|
| 18 | import NodeEnvironment from 'jest-environment-node';
|
|---|
| 19 |
|
|---|
| 20 | class MyCustomEnvironment extends NodeEnvironment {
|
|---|
| 21 | //...
|
|---|
| 22 |
|
|---|
| 23 | async handleTestEvent(event: Event, state: State) {
|
|---|
| 24 | if (event.name === 'test_start') {
|
|---|
| 25 | // ...
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 | ```
|
|---|
| 30 |
|
|---|
| 31 | 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.
|
|---|
| 32 |
|
|---|
| 33 | 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][type-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.
|
|---|
| 34 |
|
|---|
| 35 | ## Installation
|
|---|
| 36 |
|
|---|
| 37 | > Note: As of Jest 27, `jest-circus` is the default test runner, so you do not have to install it to use it.
|
|---|
| 38 |
|
|---|
| 39 | Install `jest-circus` using yarn:
|
|---|
| 40 |
|
|---|
| 41 | ```bash
|
|---|
| 42 | yarn add --dev jest-circus
|
|---|
| 43 | ```
|
|---|
| 44 |
|
|---|
| 45 | Or via npm:
|
|---|
| 46 |
|
|---|
| 47 | ```bash
|
|---|
| 48 | npm install --save-dev jest-circus
|
|---|
| 49 | ```
|
|---|
| 50 |
|
|---|
| 51 | ## Configure
|
|---|
| 52 |
|
|---|
| 53 | Configure Jest to use `jest-circus` via the [`testRunner`](https://jestjs.io/docs/configuration#testrunner-string) option:
|
|---|
| 54 |
|
|---|
| 55 | ```json
|
|---|
| 56 | {
|
|---|
| 57 | "testRunner": "jest-circus/runner"
|
|---|
| 58 | }
|
|---|
| 59 | ```
|
|---|
| 60 |
|
|---|
| 61 | Or via CLI:
|
|---|
| 62 |
|
|---|
| 63 | ```bash
|
|---|
| 64 | jest --testRunner='jest-circus/runner'
|
|---|
| 65 | ```
|
|---|