Skip to content

Commit

Permalink
fix(@jest/transform): do not attempt instrumenting .json modules (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Apr 8, 2023
1 parent 279f97c commit e5b6287
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,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

Expand Down
14 changes: 14 additions & 0 deletions packages/jest-transform/src/__tests__/shouldInstrument.test.ts
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -245,5 +251,13 @@ describe('shouldInstrument', () => {
['do/collect/coverage.js'],
);
});

it('when file is a .json module', () => {
testShouldInstrument(
'dont/collect/coverage.json',
defaultOptions,
defaultConfig,
);
});
});
});
4 changes: 4 additions & 0 deletions packages/jest-transform/src/shouldInstrument.ts
Expand Up @@ -114,5 +114,9 @@ export default function shouldInstrument(
}
}

if (filename.endsWith('.json')) {
return false;
}

return true;
}

0 comments on commit e5b6287

Please sign in to comment.