From f6ae2cbc4e7ec69dc6cb42b0730e871d46a4e314 Mon Sep 17 00:00:00 2001 From: Stephan Troyer Date: Mon, 9 Apr 2018 12:37:44 +0200 Subject: [PATCH] Move `Options.coverage` to `ProjectWorkspace.collectCoverage` (#5929) * update type definitions * Move `Options.coverage` to `ProjectWorkspace.collectCoverage` * mark collectCoverage as optional * fix failing test * update changelog --- CHANGELOG.md | 2 ++ packages/jest-editor-support/index.d.ts | 3 ++- packages/jest-editor-support/src/Runner.js | 4 ++-- .../jest-editor-support/src/__tests__/runner.test.js | 8 ++++---- packages/jest-editor-support/src/project_workspace.js | 9 +++++++++ packages/jest-editor-support/src/types.js | 1 - 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db3aa0fef0e5..09d9a4ff6785 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +* `[jest-editor-support]` Move `coverage` to `ProjectWorkspace.collectCoverage` + ([#5929](https://github.com/facebook/jest/pull/5929)) * `[jest-editor-support]` Add `coverage` option to runner ([#5836](https://github.com/facebook/jest/pull/5836)) * `[jest-haste-map]` Support extracting dynamic `import`s diff --git a/packages/jest-editor-support/index.d.ts b/packages/jest-editor-support/index.d.ts index 67230c116415..dfc7bb64c330 100644 --- a/packages/jest-editor-support/index.d.ts +++ b/packages/jest-editor-support/index.d.ts @@ -13,7 +13,6 @@ export interface SpawnOptions { } export interface Options { - coverage?: boolean; createProcess?( workspace: ProjectWorkspace, args: string[], @@ -49,11 +48,13 @@ export class ProjectWorkspace { pathToJest: string, pathToConfig: string, localJestMajorVersin: number, + collectCoverage?: boolean, ); pathToJest: string; pathToConfig: string; rootPath: string; localJestMajorVersion: number; + collectCoverage?: boolean; } export interface IParseResults { diff --git a/packages/jest-editor-support/src/Runner.js b/packages/jest-editor-support/src/Runner.js index 2f7e571da6ec..8bd124625ad6 100644 --- a/packages/jest-editor-support/src/Runner.js +++ b/packages/jest-editor-support/src/Runner.js @@ -66,10 +66,10 @@ export default class Runner extends EventEmitter { if (this.options.testFileNamePattern) { args.push(this.options.testFileNamePattern); } - if (this.options.coverage === true) { + if (this.workspace.collectCoverage === true) { args.push('--coverage'); } - if (this.options.coverage === false) { + if (this.workspace.collectCoverage === false) { args.push('--no-coverage'); } if (this.options.noColor === true) { diff --git a/packages/jest-editor-support/src/__tests__/runner.test.js b/packages/jest-editor-support/src/__tests__/runner.test.js index 3a8f59bca457..ac6557dcc4c5 100644 --- a/packages/jest-editor-support/src/__tests__/runner.test.js +++ b/packages/jest-editor-support/src/__tests__/runner.test.js @@ -183,8 +183,8 @@ describe('Runner', () => { it('calls createProcess with the --coverage arg when provided', () => { const expected = '--coverage'; - const workspace: any = {}; - const options = {coverage: true}; + const workspace: any = {collectCoverage: true}; + const options = {}; const sut = new Runner(workspace, options); sut.start(false); @@ -196,8 +196,8 @@ describe('Runner', () => { it('calls createProcess with the ---no-coverage arg when provided and false', () => { const expected = '--no-coverage'; - const workspace: any = {}; - const options = {coverage: false}; + const workspace: any = {collectCoverage: false}; + const options = {}; const sut = new Runner(workspace, options); sut.start(false); diff --git a/packages/jest-editor-support/src/project_workspace.js b/packages/jest-editor-support/src/project_workspace.js index 69aff307af0e..10c5540f5c6f 100644 --- a/packages/jest-editor-support/src/project_workspace.js +++ b/packages/jest-editor-support/src/project_workspace.js @@ -46,15 +46,24 @@ export default class ProjectWorkspace { */ localJestMajorVersion: number; + /** + * Whether test coverage should be (automatically) collected. + * + * @type {boolean} + */ + collectCoverage: ?boolean; + constructor( rootPath: string, pathToJest: string, pathToConfig: string, localJestMajorVersion: number, + collectCoverage: ?boolean, ) { this.rootPath = rootPath; this.pathToJest = pathToJest; this.pathToConfig = pathToConfig; this.localJestMajorVersion = localJestMajorVersion; + this.collectCoverage = collectCoverage; } } diff --git a/packages/jest-editor-support/src/types.js b/packages/jest-editor-support/src/types.js index 99d506a1aec2..74de73414479 100644 --- a/packages/jest-editor-support/src/types.js +++ b/packages/jest-editor-support/src/types.js @@ -20,7 +20,6 @@ import type {ChildProcess} from 'child_process'; import type ProjectWorkspace from './project_workspace'; export type Options = { - coverage?: boolean, createProcess?: ( workspace: ProjectWorkspace, args: Array,