Skip to content

Commit 133a9a1

Browse files
ronamicpojer
authored andcommitted
support multiple glob patterns for collectCoverageFrom (#5537)
* support multiple glob patterns for collectCoverageFrom * add changelog for multiple globs for collectCoverageFrom cli option * update snapshot for coverage_report.test.js
1 parent 55c342a commit 133a9a1

5 files changed

Lines changed: 38 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
`assert`, `count`, `countReset`, `dir`, `dirxml`, `group`, `groupCollapsed`,
1212
`groupEnd`, `time`, `timeEnd`
1313
([#5514](https://github.com/facebook/jest/pull/5514))
14-
* `[docs]` Add documentation for interactive snapshot mode ([#5291](https://github.com/facebook/jest/pull/5291))
15-
* `[jest-editor-support]` Add watchAll flag ([#5523](https://github.com/facebook/jest/pull/5523))
14+
* `[docs]` Add documentation for interactive snapshot mode
15+
([#5291](https://github.com/facebook/jest/pull/5291))
16+
* `[jest-editor-support]` Add watchAll flag
17+
([#5523](https://github.com/facebook/jest/pull/5523))
18+
* `[jest-cli]` Support multiple glob patterns for `collectCoverageFrom`
19+
([#5537](https://github.com/facebook/jest/pull/5537))
1620

1721
### Chore & Maintenance
1822

19-
* `[jest-config]` Allow `<rootDir>` to be used with `collectCoverageFrom` ([#5524](https://github.com/facebook/jest/pull/5524))
23+
* `[jest-config]` Allow `<rootDir>` to be used with `collectCoverageFrom`
24+
([#5524](https://github.com/facebook/jest/pull/5524))
2025

2126
## jest 22.2.2
2227

@@ -154,7 +159,8 @@
154159
* `[jest-cli]` Make Jest exit without an error when no tests are found in the
155160
case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
156161
having been passed to the CLI
157-
* `[jest-cli]` Add interactive snapshot mode ([#3831](https://github.com/facebook/jest/pull/3831))
162+
* `[jest-cli]` Add interactive snapshot mode
163+
([#3831](https://github.com/facebook/jest/pull/3831))
158164

159165
### Fixes
160166

docs/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ directory. The default cache directory can be found by calling
134134

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

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

140140
### `--colors`

integration-tests/__tests__/__snapshots__/coverage_report.test.js.snap

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ All files | 100 | 100 | 100 | 100 | |
1313
"
1414
`;
1515

16-
exports[`collects coverage only from specified files 1`] = `
16+
exports[`collects coverage only from multiple specified files 1`] = `
17+
"---------------|----------|----------|----------|----------|----------------|
18+
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
19+
---------------|----------|----------|----------|----------|----------------|
20+
All files | 100 | 100 | 100 | 100 | |
21+
other-file.js | 100 | 100 | 100 | 100 | |
22+
setup.js | 100 | 100 | 100 | 100 | |
23+
---------------|----------|----------|----------|----------|----------------|
24+
"
25+
`;
26+
27+
exports[`collects coverage only from specified file 1`] = `
1728
"----------|----------|----------|----------|----------|----------------|
1829
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
1930
----------|----------|----------|----------|----------|----------------|

integration-tests/__tests__/coverage_report.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('outputs coverage report', () => {
3333
expect(status).toBe(0);
3434
});
3535

36-
test('collects coverage only from specified files', () => {
36+
test('collects coverage only from specified file', () => {
3737
const {stdout} = runJest(DIR, [
3838
'--no-cache',
3939
'--coverage',
@@ -45,6 +45,18 @@ test('collects coverage only from specified files', () => {
4545
expect(stdout).toMatchSnapshot();
4646
});
4747

48+
test('collects coverage only from multiple specified files', () => {
49+
const {stdout} = runJest(DIR, [
50+
'--no-cache',
51+
'--coverage',
52+
'--collectCoverageFrom', // overwrites the one in package.json
53+
'setup.js',
54+
'other-file.js',
55+
]);
56+
57+
expect(stdout).toMatchSnapshot();
58+
});
59+
4860
test('collects coverage only from specified files avoiding dependencies', () => {
4961
const {stdout} = runJest(DIR, [
5062
'--no-cache',

packages/jest-cli/src/cli/args.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ export const options = {
153153
},
154154
collectCoverageFrom: {
155155
description:
156-
'relative to <rootDir> glob pattern matching the files ' +
156+
'An array of glob patterns relative to <rootDir> matching the files ' +
157157
'that coverage info needs to be collected from.',
158-
type: 'string',
158+
type: 'array',
159159
},
160160
collectCoverageOnlyFrom: {
161161
description: 'Explicit list of paths coverage will be restricted to.',

0 commit comments

Comments
 (0)