From 319c8962e0698c9727fed83ddd7dcbbe74f7d774 Mon Sep 17 00:00:00 2001 From: Meng Lin Date: Tue, 30 Oct 2018 15:30:05 -0400 Subject: [PATCH] Generate empty coverage from instrumented result code. --- packages/jest-cli/src/generateEmptyCoverage.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/jest-cli/src/generateEmptyCoverage.js b/packages/jest-cli/src/generateEmptyCoverage.js index 87be42cf3656..f609642713bb 100644 --- a/packages/jest-cli/src/generateEmptyCoverage.js +++ b/packages/jest-cli/src/generateEmptyCoverage.js @@ -9,9 +9,12 @@ import type {GlobalConfig, ProjectConfig, Path} from 'types/Config'; -import {createInstrumenter} from 'istanbul-lib-instrument'; +import {readInitialCoverage} from 'istanbul-lib-instrument'; +import {classes} from 'istanbul-lib-coverage'; import Runtime from 'jest-runtime'; +const FileCoverage = classes.FileCoverage; + export type CoverageWorkerResult = {| coverage: any, sourceMapPath: ?string, @@ -29,16 +32,13 @@ export default function( collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom, }; if (Runtime.shouldInstrument(filename, coverageOptions, config)) { - // Transform file without instrumentation first, to make sure produced - // source code is ES6 (no flowtypes etc.) and can be instrumented const transformResult = new Runtime.ScriptTransformer( config, - ).transformSource(filename, source, false); - const instrumenter = createInstrumenter(); - instrumenter.instrumentSync(transformResult.code, filename); + ).transformSource(filename, source, true); + const extracted = readInitialCoverage(transformResult.code); + return { - coverage: instrumenter.fileCoverage, - sourceMapPath: transformResult.sourceMapPath, + coverage: new FileCoverage(extracted.coverageData), }; } else { return null;