Skip to content

Commit

Permalink
fix up flow types
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbay committed Dec 17, 2016
1 parent adb3998 commit 7f68b71
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 54 deletions.
51 changes: 25 additions & 26 deletions packages/jest-cli/src/generateEmptyCoverage.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
}
};
6 changes: 3 additions & 3 deletions packages/jest-cli/src/reporters/CoverageReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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');
Expand All @@ -31,7 +31,7 @@ const isInteractive = process.stdout.isTTY && !isCI;

class CoverageReporter extends BaseReporter {
_coverageMap: CoverageMap;
_sourceMapStore: any;
_sourceMapStore: SourceMapStore;

constructor() {
super();
Expand Down
30 changes: 24 additions & 6 deletions types/TestResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,38 @@
'use strict';

import type {ConsoleBuffer} from './Console';
import type {SourceMap} from './Transform';

export type Coverage = {|
coveredSpans: Array<Object>,
uncoveredSpans: Array<Object>,
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,
Expand Down
19 changes: 0 additions & 19 deletions types/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -54,11 +42,4 @@ export type Transformer = {|
config: Config,
options?: TransformOptions,
) => string,

getEmptyCoverage: (
sourceText: string,
sourcePath: Path,
config: Config,
options?: TransformOptions,
) => Coverage
|};

0 comments on commit 7f68b71

Please sign in to comment.