diff --git a/CHANGELOG.md b/CHANGELOG.md index feea55330ed2..ea3e0acbc06e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `[jest-environment-jsdom, jest-environment-node]` Fix assignment of `customExportConditions` via `testEnvironmentOptions` when custom env subclass defines a default value ([#13989](https://github.com/facebook/jest/pull/13989)) - `[jest-matcher-utils]` Fix copying value of inherited getters ([#14007](https://github.com/facebook/jest/pull/14007)) - `[jest-snapshot]` Fix a potential bug when not using prettier and improve performance ([#14036](https://github.com/facebook/jest/pull/14036)) +- `[@jest/transform]` Do not instrument `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048)) ### Chore & Maintenance diff --git a/packages/jest-transform/src/__tests__/shouldInstrument.test.ts b/packages/jest-transform/src/__tests__/shouldInstrument.test.ts index cb1e66a38a2f..e48229f06a6f 100644 --- a/packages/jest-transform/src/__tests__/shouldInstrument.test.ts +++ b/packages/jest-transform/src/__tests__/shouldInstrument.test.ts @@ -119,6 +119,12 @@ describe('shouldInstrument', () => { ['dont/collect/coverage.js'], ); }); + + it('when file is a .json module, but matches forceCoverageMatch', () => { + testShouldInstrument('do/collect/coverage.json', defaultOptions, { + forceCoverageMatch: ['**/do/**/*.json'], + }); + }); }); describe('should return false', () => { @@ -245,5 +251,13 @@ describe('shouldInstrument', () => { ['do/collect/coverage.js'], ); }); + + it('when file is a .json module', () => { + testShouldInstrument( + 'dont/collect/coverage.json', + defaultOptions, + defaultConfig, + ); + }); }); }); diff --git a/packages/jest-transform/src/shouldInstrument.ts b/packages/jest-transform/src/shouldInstrument.ts index 837a8417d0c5..2c1a5b796f51 100644 --- a/packages/jest-transform/src/shouldInstrument.ts +++ b/packages/jest-transform/src/shouldInstrument.ts @@ -114,5 +114,9 @@ export default function shouldInstrument( } } + if (filename.endsWith('.json')) { + return false; + } + return true; }