Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update type definitions for coverageReporters #10275

Merged
merged 2 commits into from Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,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
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)
SimenB marked this conversation as resolved.
Show resolved Hide resolved

### `coverageThreshold` [object]

Default: `undefined`
Expand Down
20 changes: 17 additions & 3 deletions packages/jest-types/src/Config.ts
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 @@ -108,7 +122,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 @@ -238,7 +252,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