Skip to content

Commit

Permalink
fix: transform code for code coverage async if possible (#11852)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 8, 2021
1 parent 0e5495b commit e0b33b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[@jest/reporters]` Use async transform if available to transform files with no coverage ([#11852](https://github.com/facebook/jest/pull/11852))

### Chore & Maintenance

### Performance
Expand Down
18 changes: 11 additions & 7 deletions packages/jest-reporters/src/generateEmptyCoverage.ts
Expand Up @@ -69,13 +69,17 @@ export default async function (
const scriptTransformer = await createScriptTransformer(config);

// Transform file with instrumentation to make sure initial coverage data is well mapped to original code.
const {code} = scriptTransformer.transformSource(filename, source, {
instrument: true,
supportsDynamicImport: true,
supportsExportNamespaceFrom: true,
supportsStaticESM: true,
supportsTopLevelAwait: true,
});
const {code} = await scriptTransformer.transformSourceAsync(
filename,
source,
{
instrument: true,
supportsDynamicImport: true,
supportsExportNamespaceFrom: true,
supportsStaticESM: true,
supportsTopLevelAwait: true,
},
);
// TODO: consider passing AST
const extracted = readInitialCoverage(code);
// Check extracted initial coverage is not null, this can happen when using /* istanbul ignore file */
Expand Down

0 comments on commit e0b33b7

Please sign in to comment.