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 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..8b586d9c054c 100644 --- a/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap @@ -13,7 +13,18 @@ All files | 100 | 100 | 100 | 100 | | " `; -exports[`collects coverage only from specified files 1`] = ` +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 file 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.',