Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@jest/transform): do not attempt instrumenting .json modules #14048

Merged
merged 5 commits into from Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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 attempt instrumenting `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048))
SimenB marked this conversation as resolved.
Show resolved Hide resolved

### 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;
}