Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features

* `[jest-editor-support]` Add `coverage` option to runner
([#5836](https://github.com/facebook/jest/pull/5836))
* `[jest-haste-map]` Support extracting dynamic `import`s
([#5883](https://github.com/facebook/jest/pull/5883))
* `[expect]` Improve output format for mismatchedArgs in mock/spy calls.
Expand Down
1 change: 1 addition & 0 deletions packages/jest-editor-support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface SpawnOptions {
}

export interface Options {
coverage?: boolean;
createProcess?(
workspace: ProjectWorkspace,
args: string[],
Expand Down
6 changes: 6 additions & 0 deletions packages/jest-editor-support/src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export default class Runner extends EventEmitter {
if (this.options.testFileNamePattern) {
args.push(this.options.testFileNamePattern);
}
if (this.options.coverage === true) {
args.push('--coverage');
}
if (this.options.coverage === false) {
args.push('--no-coverage');
}

const options = {
shell: this.options.shell,
Expand Down
39 changes: 39 additions & 0 deletions packages/jest-editor-support/src/__tests__/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,45 @@ describe('Runner', () => {
expect((createProcess: any).mock.calls[0][1]).toContain('--watch');
});

it('calls createProcess with the --coverage arg when provided', () => {
const expected = '--coverage';

const workspace: any = {};
const options = {coverage: true};
const sut = new Runner(workspace, options);
sut.start(false);

const args = (createProcess: any).mock.calls[0][1];
const index = args.indexOf(expected);
expect(index).not.toBe(-1);
});

it('calls createProcess with the ---no-coverage arg when provided and false', () => {
const expected = '--no-coverage';

const workspace: any = {};
const options = {coverage: false};
const sut = new Runner(workspace, options);
sut.start(false);

const args = (createProcess: any).mock.calls[0][1];
const index = args.indexOf(expected);
expect(index).not.toBe(-1);
});

it('calls createProcess without the --coverage arg when undefined', () => {
const expected = '--coverage';

const workspace: any = {};
const options = {};
const sut = new Runner(workspace, options);
sut.start(false);

const args = (createProcess: any).mock.calls[0][1];
const index = args.indexOf(expected);
expect(index).toBe(-1);
});

it('calls createProcess with the --testNamePattern arg when provided', () => {
const expected = 'testNamePattern';

Expand Down
1 change: 1 addition & 0 deletions packages/jest-editor-support/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {ChildProcess} from 'child_process';
import type ProjectWorkspace from './project_workspace';

export type Options = {
coverage?: boolean,
createProcess?: (
workspace: ProjectWorkspace,
args: Array<string>,
Expand Down