From d7079df8b8712db4ae05476c2c202a7f4021fbfb Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 3 Apr 2023 13:20:50 +0300 Subject: [PATCH 1/4] fix(@jest/transform): do not attempt instrumenting `.json` modules --- .../src/__tests__/shouldInstrument.test.ts | 14 ++++++++++++++ packages/jest-transform/src/shouldInstrument.ts | 4 ++++ 2 files changed, 18 insertions(+) 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; } From 9a9c792571adee8f2ee3179f5a52b3c057fd03e0 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 3 Apr 2023 13:39:45 +0300 Subject: [PATCH 2/4] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64fc2fc659d3..898db7db7fc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,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/transform]` Do not attempt instrumenting `.json modules` ([#14048](https://github.com/facebook/jest/pull/14048)) ### Chore & Maintenance From 534324ac7c59500d38834dc21620b2d46ea5e231 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Wed, 5 Apr 2023 13:16:19 +0300 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b069b7e10f7..ff058df363af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +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 attempt instrumenting `.json modules` ([#14048](https://github.com/facebook/jest/pull/14048)) +- `[@jest/transform]` Do not attempt instrumenting `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048)) ### Chore & Maintenance From e4db3b20d66781108ccaf3237cb87b4521f0f540 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 8 Apr 2023 10:38:35 +0200 Subject: [PATCH 4/4] Apply suggestions from code review --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff058df363af..ea3e0acbc06e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +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 attempt instrumenting `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048)) +- `[@jest/transform]` Do not instrument `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048)) ### Chore & Maintenance