From e1ff4c4a84eca688049932e3db765a1a67ab2ab8 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Mon, 12 Feb 2018 21:00:43 +0200 Subject: [PATCH 1/3] support multiple glob patterns for collectCoverageFrom --- docs/CLI.md | 2 +- .../__snapshots__/coverage_report.test.js.snap | 11 +++++++++++ .../__tests__/coverage_report.test.js | 14 +++++++++++++- packages/jest-cli/src/cli/args.js | 4 ++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 8cfc0a5d3acd..ec1095211e21 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -134,7 +134,7 @@ directory. The default cache directory can be found by calling ### `--collectCoverageFrom=` -Relative to the root directory, glob pattern matching the files that coverage +An array of glob patterns relative to matching the files that coverage info needs to be collected from. ### `--colors` diff --git a/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap b/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap index 0fe0d842cbeb..5c62df48ce35 100644 --- a/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap @@ -13,6 +13,17 @@ All files | 100 | 100 | 100 | 100 | | " `; +exports[`collects coverage only from multiple specified files 1`] = ` +"---------------|----------|----------|----------|----------|----------------| +File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | +---------------|----------|----------|----------|----------|----------------| +All files | 100 | 100 | 100 | 100 | | + other-file.js | 100 | 100 | 100 | 100 | | + setup.js | 100 | 100 | 100 | 100 | | +---------------|----------|----------|----------|----------|----------------| +" +`; + exports[`collects coverage only from specified files 1`] = ` "----------|----------|----------|----------|----------|----------------| File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | diff --git a/integration-tests/__tests__/coverage_report.test.js b/integration-tests/__tests__/coverage_report.test.js index 25a132470cf9..ae52de826ae5 100644 --- a/integration-tests/__tests__/coverage_report.test.js +++ b/integration-tests/__tests__/coverage_report.test.js @@ -33,7 +33,7 @@ test('outputs coverage report', () => { expect(status).toBe(0); }); -test('collects coverage only from specified files', () => { +test('collects coverage only from specified file', () => { const {stdout} = runJest(DIR, [ '--no-cache', '--coverage', @@ -45,6 +45,18 @@ test('collects coverage only from specified files', () => { expect(stdout).toMatchSnapshot(); }); +test('collects coverage only from multiple specified files', () => { + const {stdout} = runJest(DIR, [ + '--no-cache', + '--coverage', + '--collectCoverageFrom', // overwrites the one in package.json + 'setup.js', + 'other-file.js', + ]); + + expect(stdout).toMatchSnapshot(); +}); + test('collects coverage only from specified files avoiding dependencies', () => { const {stdout} = runJest(DIR, [ '--no-cache', diff --git a/packages/jest-cli/src/cli/args.js b/packages/jest-cli/src/cli/args.js index a3eda097a6c3..6dbacfd14138 100644 --- a/packages/jest-cli/src/cli/args.js +++ b/packages/jest-cli/src/cli/args.js @@ -153,9 +153,9 @@ export const options = { }, collectCoverageFrom: { description: - 'relative to glob pattern matching the files ' + + 'An array of glob patterns relative to matching the files ' + 'that coverage info needs to be collected from.', - type: 'string', + type: 'array', }, collectCoverageOnlyFrom: { description: 'Explicit list of paths coverage will be restricted to.', From a1d34db23f26b04adff09cb82c9182919d57ec6a Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Mon, 12 Feb 2018 21:16:05 +0200 Subject: [PATCH 2/3] add changelog for multiple globs for collectCoverageFrom cli option --- CHANGELOG.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5296369a8e8..6bfcad66b879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,17 @@ `assert`, `count`, `countReset`, `dir`, `dirxml`, `group`, `groupCollapsed`, `groupEnd`, `time`, `timeEnd` ([#5514](https://github.com/facebook/jest/pull/5514)) -* `[docs]` Add documentation for interactive snapshot mode ([#5291](https://github.com/facebook/jest/pull/5291)) -* `[jest-editor-support]` Add watchAll flag ([#5523](https://github.com/facebook/jest/pull/5523)) +* `[docs]` Add documentation for interactive snapshot mode + ([#5291](https://github.com/facebook/jest/pull/5291)) +* `[jest-editor-support]` Add watchAll flag + ([#5523](https://github.com/facebook/jest/pull/5523)) +* `[jest-cli]` Support multiple glob patterns for `collectCoverageFrom` + ([#5537](https://github.com/facebook/jest/pull/5537)) ### Chore & Maintenance -* `[jest-config]` Allow `` to be used with `collectCoverageFrom` ([#5524](https://github.com/facebook/jest/pull/5524)) +* `[jest-config]` Allow `` to be used with `collectCoverageFrom` + ([#5524](https://github.com/facebook/jest/pull/5524)) ## jest 22.2.2 @@ -154,7 +159,8 @@ * `[jest-cli]` Make Jest exit without an error when no tests are found in the case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options having been passed to the CLI -* `[jest-cli]` Add interactive snapshot mode ([#3831](https://github.com/facebook/jest/pull/3831)) +* `[jest-cli]` Add interactive snapshot mode + ([#3831](https://github.com/facebook/jest/pull/3831)) ### Fixes From f251fe71c4d70b8ff03c43fa9dca48aaace61b46 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Mon, 12 Feb 2018 21:32:13 +0200 Subject: [PATCH 3/3] update snapshot for coverage_report.test.js --- .../__tests__/__snapshots__/coverage_report.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap b/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap index 5c62df48ce35..8b586d9c054c 100644 --- a/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap @@ -24,7 +24,7 @@ All files | 100 | 100 | 100 | 100 | | " `; -exports[`collects coverage only from specified files 1`] = ` +exports[`collects coverage only from specified file 1`] = ` "----------|----------|----------|----------|----------|----------------| File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | ----------|----------|----------|----------|----------|----------------|