Skip to content

Commit

Permalink
chore: update type definitions for coverageReporters (#10275)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-a-doctor authored Jul 30, 2020
1 parent 01b93d4 commit e3f4f93
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `[jest-jasmine2]` Remove usage of `Function` type ([#10216](https://github.com/facebook/jest/pull/10216))
- `[jest-resolve]` Improve types ([#10239](https://github.com/facebook/jest/pull/10239))
- `[docs]` Clarify the [`jest.requireActual(moduleName)`](https://jestjs.io/docs/en/jest-object#jestrequireactualmodulename) example
- `[jest-types]` Refine typings of `coverageReporters` ([#10275](https://github.com/facebook/jest/pull/10275))

### Performance

Expand Down
4 changes: 3 additions & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Indicates which provider should be used to instrument code for coverage. Allowed

Note that using `v8` is considered experimental. This uses V8's builtin code coverage rather than one based on Babel. It is not as well tested, and it has also improved in the last few releases of Node. Using the latest versions of node (v14 at the time of this writing) will yield better results.

### `coverageReporters` [array\<string | [string,any]>]
### `coverageReporters` [array\<string | [string, options]>]

Default: `["json", "lcov", "text", "clover"]`

Expand All @@ -207,6 +207,8 @@ _Note: You can pass additional options to the istanbul reporter using the tuple
["json", ["lcov", {"projectRoot": "../../"}]]
```

For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts).

### `coverageThreshold` [object]

Default: `undefined`
Expand Down
20 changes: 17 additions & 3 deletions packages/jest-types/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ export type HasteConfig = {
throwOnModuleCollision?: boolean;
};

export type CoverageReporterName = keyof ReportOptions;

export type CoverageReporterWithOptions<
K = CoverageReporterName
> = K extends CoverageReporterName
? ReportOptions[K] extends never
? never
: [K, Partial<ReportOptions[K]>]
: never;

export type CoverageReporters = Array<
CoverageReporterName | CoverageReporterWithOptions
>;

export type ReporterConfig = [string, Record<string, unknown>];
export type TransformerConfig = [string, Record<string, unknown>];

Expand All @@ -39,7 +53,7 @@ export type DefaultOptions = {
clearMocks: boolean;
collectCoverage: boolean;
coveragePathIgnorePatterns: Array<string>;
coverageReporters: Array<string | [string, any]>;
coverageReporters: Array<CoverageReporterName>;
coverageProvider: CoverageProvider;
errorOnDeprecated: boolean;
expand: boolean;
Expand Down Expand Up @@ -109,7 +123,7 @@ export type InitialOptions = Partial<{
coverageDirectory: string;
coveragePathIgnorePatterns: Array<string>;
coverageProvider: CoverageProvider;
coverageReporters: Array<string>;
coverageReporters: CoverageReporters;
coverageThreshold: {
global: {
[key: string]: number;
Expand Down Expand Up @@ -240,7 +254,7 @@ export type GlobalConfig = {
coverageDirectory: string;
coveragePathIgnorePatterns?: Array<string>;
coverageProvider: CoverageProvider;
coverageReporters: Array<keyof ReportOptions | [keyof ReportOptions, any]>;
coverageReporters: CoverageReporters;
coverageThreshold?: CoverageThreshold;
detectLeaks: boolean;
detectOpenHandles: boolean;
Expand Down

0 comments on commit e3f4f93

Please sign in to comment.