Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Fixes

- `[jest-runtime]` Fix issue where user cannot utilize dynamic import despite specifying `--experimental-vm-modules` Node option ([#15842](https://github.com/jestjs/jest/pull/15842))
- `[jest-config]` Fix issue where user cannot toggle `collectCoverage` at project level ([#15588](https://github.com/jestjs/jest/issues/15588))

## 30.2.0

Expand Down
1 change: 0 additions & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ exports[`--showConfig outputs config info and exits 1`] = `
"bail": 0,
"changedFilesWithAncestor": false,
"ci": true,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "<<REPLACED_ROOT_DIR>>/coverage",
"coverageProvider": "babel",
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/ValidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export const initialProjectOptions: Config.InitialProjectOptions = {
cache: true,
cacheDirectory: '/tmp/user/jest',
clearMocks: false,
collectCoverage: false,
collectCoverageFrom: ['src', '!public'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const groupOptions = (
cache: options.cache,
cacheDirectory: options.cacheDirectory,
clearMocks: options.clearMocks,
collectCoverage: options.collectCoverage,
collectCoverageFrom: options.collectCoverageFrom,
coverageDirectory: options.coverageDirectory,
coveragePathIgnorePatterns: options.coveragePathIgnorePatterns,
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ export default async function normalize(
if (!options.coverageDirectory) {
options.coverageDirectory = path.resolve(options.rootDir, 'coverage');
}
if (!Object.hasOwn(options, 'collectCoverage')) {
options.collectCoverage = undefined;
}

setupBabelJest(options);
// TODO: Type this properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ describe('ScriptTransformer', () => {
config = makeProjectConfig({
cache: true,
cacheDirectory: '/cache/',
collectCoverage: undefined,
id: 'test',
rootDir: '/',
transformIgnorePatterns: ['/node_modules/'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports[`ScriptTransformer in async mode, passes expected transform options to g
"cache": true,
"cacheDirectory": "/cache/",
"clearMocks": false,
"collectCoverage": undefined,
"collectCoverageFrom": Array [
"src",
"!public",
Expand Down Expand Up @@ -177,6 +178,7 @@ exports[`ScriptTransformer passes expected transform options to getCacheKey 1`]
"cache": true,
"cacheDirectory": "/cache/",
"clearMocks": false,
"collectCoverage": undefined,
"collectCoverageFrom": Array [
"src",
"!public",
Expand Down Expand Up @@ -302,6 +304,7 @@ exports[`ScriptTransformer passes expected transform options to getCacheKeyAsync
"cache": true,
"cacheDirectory": "/cache/",
"clearMocks": false,
"collectCoverage": undefined,
"collectCoverageFrom": Array [
"src",
"!public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ describe('shouldInstrument', () => {
}),
changedFiles: undefined,
};
const defaultConfig = makeProjectConfig({rootDir: '/'});
const defaultConfig = makeProjectConfig({
collectCoverage: undefined,
rootDir: '/',
});
describe('should return true', () => {
const testShouldInstrument = (
filename = defaultFilename,
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-transform/src/shouldInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export default function shouldInstrument(
config: Config.ProjectConfig,
loadedFilenames?: Array<string>,
): boolean {
if (!options.collectCoverage) {
// Do not instrument when `collectCoverage` is toggled off global or project-wide
if (
!options.collectCoverage ||
(typeof config.collectCoverage === 'boolean' && !config.collectCoverage)
) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export type ProjectConfig = {
cache: boolean;
cacheDirectory: string;
clearMocks: boolean;
collectCoverage?: boolean;
collectCoverageFrom: Array<string>;
coverageDirectory: string;
coveragePathIgnorePatterns: Array<string>;
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = {
cache: false,
cacheDirectory: '/test_cache_dir/',
clearMocks: false,
collectCoverage: undefined,
collectCoverageFrom: ['src', '!public'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [],
Expand Down
Loading