From 7f68b71193ce6cf7f9f518bb1a7b57868e924317 Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Sat, 17 Dec 2016 18:31:46 -0500 Subject: [PATCH] fix up flow types --- .../jest-cli/src/generateEmptyCoverage.js | 51 +++++++++---------- .../src/reporters/CoverageReporter.js | 6 +-- types/TestResult.js | 30 ++++++++--- types/Transform.js | 19 ------- 4 files changed, 52 insertions(+), 54 deletions(-) diff --git a/packages/jest-cli/src/generateEmptyCoverage.js b/packages/jest-cli/src/generateEmptyCoverage.js index 55fab2c4105f..44a765c5b307 100644 --- a/packages/jest-cli/src/generateEmptyCoverage.js +++ b/packages/jest-cli/src/generateEmptyCoverage.js @@ -1,30 +1,29 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @flow - */ - -'use strict'; - -import type {Config, Path} from 'types/Config'; - -const IstanbulInstrument = require('istanbul-lib-instrument'); - -const {transformSource, shouldInstrument} = require('jest-runtime'); - -module.exports = function(source: string, filename: Path, config: Config) { - if (shouldInstrument(filename, config)) { - // Transform file without instrumentation first, to make sure produced - // source code is ES6 (no flowtypes etc.) and can be instrumented +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ +'use strict'; + +import type {Config, Path} from 'types/Config'; + +const IstanbulInstrument = require('istanbul-lib-instrument'); + +const {transformSource, shouldInstrument} = require('jest-runtime'); + +module.exports = function(source: string, filename: Path, config: Config) { + if (shouldInstrument(filename, config)) { + // Transform file without instrumentation first, to make sure produced + // source code is ES6 (no flowtypes etc.) and can be instrumented source = transformSource(filename, config, source, false); const instrumenter = IstanbulInstrument.createInstrumenter(); - instrumenter.instrumentSync(source, filename); + instrumenter.instrumentSync(source, filename); return instrumenter.fileCoverage; - } else { + } else { return null; - } -}; + } +}; diff --git a/packages/jest-cli/src/reporters/CoverageReporter.js b/packages/jest-cli/src/reporters/CoverageReporter.js index a82b7b854b34..0f7326f4d597 100644 --- a/packages/jest-cli/src/reporters/CoverageReporter.js +++ b/packages/jest-cli/src/reporters/CoverageReporter.js @@ -9,7 +9,7 @@ */ 'use strict'; -import type {AggregatedResult, CoverageMap, TestResult} from 'types/TestResult'; +import type {AggregatedResult, CoverageMap, SourceMapStore, TestResult} from 'types/TestResult'; import type {Config} from 'types/Config'; import type {RunnerContext} from 'types/Reporters'; @@ -19,7 +19,7 @@ const {clearLine} = require('jest-util'); const {createReporter} = require('istanbul-api'); const chalk = require('chalk'); const fs = require('fs'); -const generateEmptyCoverage = require('../generateEmptyCoverage'); +const generateEmptyCoverage = require('../generateEmptyCoverage'); const isCI = require('is-ci'); const istanbulCoverage = require('istanbul-lib-coverage'); const libSourceMaps = require('istanbul-lib-source-maps'); @@ -31,7 +31,7 @@ const isInteractive = process.stdout.isTTY && !isCI; class CoverageReporter extends BaseReporter { _coverageMap: CoverageMap; - _sourceMapStore: any; + _sourceMapStore: SourceMapStore; constructor() { super(); diff --git a/types/TestResult.js b/types/TestResult.js index 9cb6b4b5019a..a74ada6ea851 100644 --- a/types/TestResult.js +++ b/types/TestResult.js @@ -10,20 +10,38 @@ 'use strict'; import type {ConsoleBuffer} from './Console'; +import type {SourceMap} from './Transform'; -export type Coverage = {| - coveredSpans: Array, - uncoveredSpans: Array, - sourceText: string, +export type FileCoverage = {| + path: string, + s: { [statementId: number]: number }, + b: { [branchId: number]: number }, + f: { [functionId: number]: number }, + l: { [lineId: number]: number }, + fnMap: { [functionId: number]: any }, + statementMap: { [statementId: number]: any }, + branchMap: { [branchId: number]: any }, + inputSourceMap?: SourceMap, |}; +export type Coverage = { + [filePath: string]: FileCoverage, +}; + export type CoverageMap = {| merge: (data: Object) => void, getCoverageSummary: () => Object, - data: Object, - addFileCoverage: (fileCoverage: Object) => void, + data: Coverage, + addFileCoverage: (fileCoverage: FileCoverage) => void, |}; +export class SourceMapStore { + transformCoverage: (coverageMap: CoverageMap) => { + map: CoverageMap, + sourceFinder: any + } +} + export type Error = {| message: string, stack: ?string, diff --git a/types/Transform.js b/types/Transform.js index da061bad0ad8..caf6f2336fd6 100644 --- a/types/Transform.js +++ b/types/Transform.js @@ -21,18 +21,6 @@ export type SourceMap = {| version: number, |}; -export type Coverage = {| - path: string, - s: { [statementId: number]: number }, - b: { [branchId: number]: number }, - f: { [functionId: number]: number }, - l: { [lineId: number]: number }, - fnMap: { [functionId: number]: any }, - statementMap: { [statementId: number]: any }, - branchMap: { [branchId: number]: any }, - inputSourceMap: ?SourceMap, -|} - export type TransformOptions = {| instrument: boolean, watch: boolean, @@ -54,11 +42,4 @@ export type Transformer = {| config: Config, options?: TransformOptions, ) => string, - - getEmptyCoverage: ( - sourceText: string, - sourcePath: Path, - config: Config, - options?: TransformOptions, - ) => Coverage |};