Skip to content

Commit

Permalink
fix: coverage config moved to project (jestjs#9628)
Browse files Browse the repository at this point in the history
Moved the following config props from globalConfig to projectConfig:
collectCoverageFrom, collectCoverageOnlyFrom, coverageThreshold

You can now specify those properties per project.

As a side effect, they were removed from the whitelist of watch-able properties.
  • Loading branch information
Roy Razon committed Mar 25, 2020
1 parent cd98198 commit 6f382f3
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 152 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features

- `[jest-config]` [**BREAKING**] Move coverage options to project config ([#9633](https://github.com/facebook/jest/pull/9633))
- `[jest-runtime]` Require stack when a module cannot be resolved ([#9681](https://github.com/facebook/jest/pull/9681))
- `[jest-config]` Support ESM config files with `.js` extension ([#9573](https://github.com/facebook/jest/pull/9573)).
- `[jest-runtime]` Override `module.createRequire` to return a Jest-compatible `require` function ([#9469](https://github.com/facebook/jest/pull/9469))
Expand Down
6 changes: 3 additions & 3 deletions TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
changedFilesWithAncestor: false,
changedSince: '',
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: null,
coverageDirectory: 'coverage',
coverageProvider: 'babel',
coverageReporters: [],
coverageThreshold: {global: {}},
detectLeaks: false,
detectOpenHandles: false,
enabledTestsMap: null,
Expand Down Expand Up @@ -71,7 +68,10 @@ const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = {
cache: false,
cacheDirectory: '/test_cache_dir/',
clearMocks: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: null,
coveragePathIgnorePatterns: [],
coverageThreshold: {global: {}},
cwd: '/test_root_dir/',
detectLeaks: false,
detectOpenHandles: false,
Expand Down
2 changes: 0 additions & 2 deletions docs/WatchPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ For stability and safety reasons, only part of the global configuration keys can
- [`bail`](configuration.html#bail-number--boolean)
- [`changedSince`](cli.html#--changedsince)
- [`collectCoverage`](configuration.html#collectcoverage-boolean)
- [`collectCoverageFrom`](configuration.html#collectcoveragefrom-array)
- [`collectCoverageOnlyFrom`](configuration.html#collectcoverageonlyfrom-array)
- [`coverageDirectory`](configuration.html#coveragedirectory-string)
- [`coverageReporters`](configuration.html#coveragereporters-arraystring)
- [`notify`](configuration.html#notify-boolean)
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"cache": false,
"cacheDirectory": "/tmp/jest",
"clearMocks": false,
"collectCoverageFrom": [],
"coveragePathIgnorePatterns": [
"/node_modules/"
],
Expand Down Expand Up @@ -82,7 +83,6 @@ exports[`--showConfig outputs config info and exits 1`] = `
"bail": 0,
"changedFilesWithAncestor": false,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "<<REPLACED_ROOT_DIR>>/coverage",
"coverageProvider": "babel",
"coverageReporters": [
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,9 @@ const groupOptions = (
changedFilesWithAncestor: options.changedFilesWithAncestor,
changedSince: options.changedSince,
collectCoverage: options.collectCoverage,
collectCoverageFrom: options.collectCoverageFrom,
collectCoverageOnlyFrom: options.collectCoverageOnlyFrom,
coverageDirectory: options.coverageDirectory,
coverageProvider: options.coverageProvider,
coverageReporters: options.coverageReporters,
coverageThreshold: options.coverageThreshold,
detectLeaks: options.detectLeaks,
detectOpenHandles: options.detectOpenHandles,
enabledTestsMap: options.enabledTestsMap,
Expand Down Expand Up @@ -167,7 +164,10 @@ const groupOptions = (
cache: options.cache,
cacheDirectory: options.cacheDirectory,
clearMocks: options.clearMocks,
collectCoverageFrom: options.collectCoverageFrom,
collectCoverageOnlyFrom: options.collectCoverageOnlyFrom,
coveragePathIgnorePatterns: options.coveragePathIgnorePatterns,
coverageThreshold: options.coverageThreshold,
cwd: options.cwd,
dependencyExtractor: options.dependencyExtractor,
detectLeaks: options.detectLeaks,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getNoTestsFoundMessage returns correct message when monitoring only changed 1`] = `"<bold>No tests found related to files changed since last commit.</>"`;
exports[`getNoTestsFoundMessage returns correct message when monitoring only changed 1`] = `
"<bold>No tests found related to files changed since last commit.</><dim></>
<dim>Run Jest without \`-o\` or with \`--all\` to run all tests.</>"
`;
exports[`getNoTestsFoundMessage returns correct message when monitoring only failures 1`] = `
"<bold>No failed test found.</>
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-core/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,8 @@ describe('Watch mode flows', () => {
${'✖︎'} | ${'changedFilesWithAncestor'}
${'✔︎'} | ${'changedSince'}
${'✔︎'} | ${'collectCoverage'}
${'✔︎'} | ${'collectCoverageFrom'}
${'✔︎'} | ${'collectCoverageOnlyFrom'}
${'✔︎'} | ${'coverageDirectory'}
${'✔︎'} | ${'coverageReporters'}
${'✖︎'} | ${'coverageThreshold'}
${'✖︎'} | ${'detectLeaks'}
${'✖︎'} | ${'detectOpenHandles'}
${'✖︎'} | ${'enabledTestsMap'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ exports[`prints the config object 1`] = `
"cache": false,
"cacheDirectory": "/test_cache_dir/",
"clearMocks": false,
"collectCoverageFrom": [],
"collectCoverageOnlyFrom": null,
"coveragePathIgnorePatterns": [],
"coverageThreshold": {
"global": {}
},
"cwd": "/test_root_dir/",
"detectLeaks": false,
"detectOpenHandles": false,
Expand Down Expand Up @@ -68,14 +73,9 @@ exports[`prints the config object 1`] = `
"changedFilesWithAncestor": false,
"changedSince": "",
"collectCoverage": false,
"collectCoverageFrom": [],
"collectCoverageOnlyFrom": null,
"coverageDirectory": "coverage",
"coverageProvider": "babel",
"coverageReporters": [],
"coverageThreshold": {
"global": {}
},
"detectLeaks": false,
"detectOpenHandles": false,
"enabledTestsMap": null,
Expand Down
8 changes: 0 additions & 8 deletions packages/jest-core/src/lib/update_global_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ export default (
newConfig.collectCoverage = options.collectCoverage || false;
}

if (options.collectCoverageFrom !== undefined) {
newConfig.collectCoverageFrom = options.collectCoverageFrom;
}

if (options.collectCoverageOnlyFrom !== undefined) {
newConfig.collectCoverageOnlyFrom = options.collectCoverageOnlyFrom;
}

if (options.coverageDirectory !== undefined) {
newConfig.coverageDirectory = options.coverageDirectory;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ export default function watch(
bail,
changedSince,
collectCoverage,
collectCoverageFrom,
collectCoverageOnlyFrom,
coverageDirectory,
coverageReporters,
mode,
Expand All @@ -122,8 +120,6 @@ export default function watch(
bail,
changedSince,
collectCoverage,
collectCoverageFrom,
collectCoverageOnlyFrom,
coverageDirectory,
coverageReporters,
mode,
Expand Down
Loading

0 comments on commit 6f382f3

Please sign in to comment.