You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`[jest-reporters]` Pass `reporterContext` to custom reporter constructors as third argument ([#12657](https://github.com/facebook/jest/pull/12657))
41
42
-`[jest-resolve]`[**BREAKING**] Add support for `package.json``exports` ([#11961](https://github.com/facebook/jest/pull/11961), [#12373](https://github.com/facebook/jest/pull/12373))
42
43
-`[jest-resolve, jest-runtime]` Add support for `data:` URI import and mock ([#12392](https://github.com/facebook/jest/pull/12392))
43
44
-`[jest-resolve, jest-runtime]` Add support for async resolver ([#11540](https://github.com/facebook/jest/pull/11540))
Copy file name to clipboardExpand all lines: docs/Configuration.md
+38-35Lines changed: 38 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -822,73 +822,76 @@ When using multi-project runner, it's recommended to add a `displayName` for eac
822
822
823
823
Default: `undefined`
824
824
825
-
Use this configuration option to add custom reporters to Jest. A custom reporter is a class that implements `onRunStart`, `onTestStart`, `onTestResult`, `onRunComplete` methods that will be called when any of those events occurs.
826
-
827
-
If custom reporters are specified, the default Jest reporters will be overridden. To keep default reporters, `default` can be passed as a module name.
828
-
829
-
This will override default reporters:
825
+
Use this configuration option to add reporters to Jest. It must be a list of reporter names, additional options can be passed to a reporter using the tuple form:
This will use custom reporter in addition to default reporters that Jest provides:
836
+
#### Default Reporter
837
+
838
+
If custom reporters are specified, the default Jest reporter will be overridden. If you wish to keep it, `'default'` must be passed as a reporters name:
Custom reporter modules must define a class that takes a `GlobalConfig` and reporter options as constructor arguments:
859
+
#### Custom Reporters
857
860
858
-
Example reporter:
861
+
:::tip
862
+
863
+
Hungry for reporters? Take a look at long list of [awesome reporters](https://github.com/jest-community/awesome-jest/blob/main/README.md#reporters) from Awesome Jest.
864
+
865
+
:::
859
866
860
-
```js title="my-custom-reporter.js"
861
-
classMyCustomReporter {
862
-
constructor(globalConfig, options) {
867
+
Custom reporter module must export a class that takes `globalConfig`, `reporterOptions` and `reporterContext` as constructor arguments and implements at least `onRunComplete()` method (for the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts)):
console.log('options for this reporter from Jest config: ', this._options);
881
+
console.log('reporter context passed from test scheduler: ', this._context);
871
882
}
872
-
}
873
883
874
-
module.exports= MyCustomReporter;
875
-
// or export default MyCustomReporter;
876
-
```
877
-
878
-
Custom reporters can also force Jest to exit with non-0 code by returning an Error from `getLastError()` methods
879
-
880
-
```js
881
-
classMyCustomReporter {
882
-
// ...
884
+
// Optionally, reporters can force Jest to exit with non zero code by returning
885
+
// an `Error` from `getLastError()` method.
883
886
getLastError() {
884
887
if (this._shouldFail) {
885
-
returnnewError('my-custom-reporter.js reported an error');
888
+
returnnewError('Custom error reported!');
886
889
}
887
890
}
888
891
}
889
-
```
890
892
891
-
For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts)
0 commit comments