Skip to content

Commit

Permalink
support multiple glob patterns for collectCoverageFrom (#5537)
Browse files Browse the repository at this point in the history
* support multiple glob patterns for collectCoverageFrom

* add changelog for multiple globs for collectCoverageFrom cli option

* update snapshot for coverage_report.test.js
  • Loading branch information
ronami authored and cpojer committed Feb 12, 2018
1 parent 55c342a commit 133a9a1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<rootDir>` to be used with `collectCoverageFrom` ([#5524](https://github.com/facebook/jest/pull/5524))
* `[jest-config]` Allow `<rootDir>` to be used with `collectCoverageFrom`
([#5524](https://github.com/facebook/jest/pull/5524))

## jest 22.2.2

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ directory. The default cache directory can be found by calling

### `--collectCoverageFrom=<glob>`

Relative to the root directory, glob pattern matching the files that coverage
An array of glob patterns relative to <rootDir> matching the files that coverage
info needs to be collected from.

### `--colors`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
----------|----------|----------|----------|----------|----------------|
Expand Down
14 changes: 13 additions & 1 deletion integration-tests/__tests__/coverage_report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ export const options = {
},
collectCoverageFrom: {
description:
'relative to <rootDir> glob pattern matching the files ' +
'An array of glob patterns relative to <rootDir> 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.',
Expand Down

0 comments on commit 133a9a1

Please sign in to comment.