Skip to content

Commit 9e43038

Browse files
author
Nathan L Smith
committed
Coverage option for editor support
When using the Jest extension in vscode, running coverage is often slow so it would be nice to be able to turn it on and off as needed. Add a coverage option to the runner.
1 parent abb6321 commit 9e43038

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Features
44

5+
* `[jest-editor-support]` Add `coverage` option to runner
6+
([#5836](https://github.com/facebook/jest/pull/5836))
57
* `[expect]` Improve output format for mismatchedArgs in mock/spy calls.
68
([#5846](https://github.com/facebook/jest/pull/5846))
79
* `[jest-cli]` Add support for using `--coverage` in combination with watch

packages/jest-editor-support/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface SpawnOptions {
1313
}
1414

1515
export interface Options {
16+
coverage?: boolean;
1617
createProcess?(
1718
workspace: ProjectWorkspace,
1819
args: string[],

packages/jest-editor-support/src/Runner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export default class Runner extends EventEmitter {
6666
if (this.options.testFileNamePattern) {
6767
args.push(this.options.testFileNamePattern);
6868
}
69+
if (this.options.coverage === true) {
70+
args.push('--coverage');
71+
}
72+
if (this.options.coverage === false) {
73+
args.push('--no-coverage');
74+
}
6975

7076
const options = {
7177
shell: this.options.shell,

packages/jest-editor-support/src/__tests__/runner.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,45 @@ describe('Runner', () => {
180180
expect((createProcess: any).mock.calls[0][1]).toContain('--watch');
181181
});
182182

183+
it('calls createProcess with the --coverage arg when provided', () => {
184+
const expected = '--coverage';
185+
186+
const workspace: any = {};
187+
const options = {coverage: true};
188+
const sut = new Runner(workspace, options);
189+
sut.start(false);
190+
191+
const args = (createProcess: any).mock.calls[0][1];
192+
const index = args.indexOf(expected);
193+
expect(index).not.toBe(-1);
194+
});
195+
196+
it('calls createProcess with the ---no-coverage arg when provided and false', () => {
197+
const expected = '--no-coverage';
198+
199+
const workspace: any = {};
200+
const options = {coverage: false};
201+
const sut = new Runner(workspace, options);
202+
sut.start(false);
203+
204+
const args = (createProcess: any).mock.calls[0][1];
205+
const index = args.indexOf(expected);
206+
expect(index).not.toBe(-1);
207+
});
208+
209+
it('calls createProcess without the --coverage arg when undefined', () => {
210+
const expected = '--coverage';
211+
212+
const workspace: any = {};
213+
const options = {};
214+
const sut = new Runner(workspace, options);
215+
sut.start(false);
216+
217+
const args = (createProcess: any).mock.calls[0][1];
218+
const index = args.indexOf(expected);
219+
expect(index).toBe(-1);
220+
});
221+
183222
it('calls createProcess with the --testNamePattern arg when provided', () => {
184223
const expected = 'testNamePattern';
185224

packages/jest-editor-support/src/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {ChildProcess} from 'child_process';
2020
import type ProjectWorkspace from './project_workspace';
2121

2222
export type Options = {
23+
coverage?: boolean,
2324
createProcess?: (
2425
workspace: ProjectWorkspace,
2526
args: Array<string>,

0 commit comments

Comments
 (0)