Skip to content

Commit

Permalink
Stop using istanbul-api (#8294)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell authored and SimenB committed Apr 22, 2019
1 parent 65b48a7 commit f3e3d9f
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@

- `[expect]` Fix label and add opposite assertion for toEqual tests ([#8288](https://github.com/facebook/jest/pull/8288))
- `[docs]` Mention Jest MongoDB Preset ([#8318](https://github.com/facebook/jest/pull/8318))
- `[@jest/reporters]` Migrate away from `istanbul-api` ([#8294](https://github.com/facebook/jest/pull/8294))

### Performance

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -43,8 +43,9 @@
"glob": "^7.1.1",
"graceful-fs": "^4.1.15",
"isbinaryfile": "^4.0.0",
"istanbul-api": "^2.0.8",
"istanbul-lib-coverage": "^2.0.2",
"istanbul-lib-report": "^2.0.4",
"istanbul-reports": "^2.1.1",
"jest-junit": "^6.2.1",
"jest-silent-reporter": "^0.1.2",
"jest-snapshot-serializer-raw": "^1.1.0",
Expand Down
21 changes: 0 additions & 21 deletions packages/jest-reporters/istanbul-api.d.ts

This file was deleted.

5 changes: 4 additions & 1 deletion packages/jest-reporters/package.json
Expand Up @@ -12,10 +12,11 @@
"chalk": "^2.0.1",
"exit": "^0.1.2",
"glob": "^7.1.2",
"istanbul-api": "^2.1.1",
"istanbul-lib-coverage": "^2.0.2",
"istanbul-lib-instrument": "^3.0.1",
"istanbul-lib-report": "^2.0.4",
"istanbul-lib-source-maps": "^3.0.1",
"istanbul-reports": "^2.1.1",
"jest-haste-map": "^24.7.1",
"jest-resolve": "^24.7.1",
"jest-runtime": "^24.7.1",
Expand All @@ -31,7 +32,9 @@
"@types/glob": "^7.1.1",
"@types/istanbul-lib-coverage": "^2.0.0",
"@types/istanbul-lib-instrument": "^1.7.2",
"@types/istanbul-lib-report": "^1.1.0",
"@types/istanbul-lib-source-maps": "^1.2.1",
"@types/istanbul-reports": "^1.1.0",
"@types/node-notifier": "^5.4.0",
"@types/slash": "^2.0.0",
"@types/string-length": "^2.0.0",
Expand Down
15 changes: 7 additions & 8 deletions packages/jest-reporters/src/__tests__/coverage_reporter.test.js
Expand Up @@ -5,23 +5,22 @@
* LICENSE file in the root directory of this source tree.
*/

jest.mock('istanbul-lib-source-maps').mock('istanbul-api');
jest
.mock('istanbul-lib-source-maps')
.mock('istanbul-lib-report', () => ({
createContext: jest.fn(),
summarizers: {pkg: jest.fn(() => ({visit: jest.fn()}))},
}))
.mock('istanbul-reports');

let libCoverage;
let libSourceMaps;
let CoverageReporter;
let istanbulApi;

import path from 'path';
import mock from 'mock-fs';

beforeEach(() => {
istanbulApi = require('istanbul-api');
istanbulApi.createReporter = jest.fn(() => ({
addAll: jest.fn(),
write: jest.fn(),
}));

CoverageReporter = require('../coverage_reporter').default;
libCoverage = require('istanbul-lib-coverage');
libSourceMaps = require('istanbul-lib-source-maps');
Expand Down
21 changes: 10 additions & 11 deletions packages/jest-reporters/src/coverage_reporter.ts
Expand Up @@ -5,14 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

// TODO: Remove this
/// <reference path="../istanbul-api.d.ts" />

import path from 'path';
import {Config} from '@jest/types';
import {AggregatedResult, TestResult} from '@jest/test-result';
import {clearLine, isInteractive} from 'jest-util';
import {createReporter} from 'istanbul-api';
import istanbulReport from 'istanbul-lib-report';
import istanbulReports from 'istanbul-reports';
import chalk from 'chalk';
import istanbulCoverage, {
CoverageMap,
Expand Down Expand Up @@ -88,20 +86,21 @@ export default class CoverageReporter extends BaseReporter {
this._coverageMap,
);

const reporter = createReporter();
try {
if (this._globalConfig.coverageDirectory) {
reporter.dir = this._globalConfig.coverageDirectory;
}

const reportContext = istanbulReport.createContext({
dir: this._globalConfig.coverageDirectory,
sourceFinder,
});
const coverageReporters = this._globalConfig.coverageReporters || [];

if (!this._globalConfig.useStderr && coverageReporters.length < 1) {
coverageReporters.push('text-summary');
}

reporter.addAll(coverageReporters);
reporter.write(map, sourceFinder && {sourceFinder});
const tree = istanbulReport.summarizers.pkg(map);
coverageReporters.forEach(reporter => {
tree.visit(istanbulReports.create(reporter, {}), reportContext);
});
aggregatedResults.coverageMap = map;
} catch (e) {
console.error(
Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/package.json
Expand Up @@ -14,6 +14,7 @@
"types": "build/index.d.ts",
"dependencies": {
"@types/istanbul-lib-coverage": "^2.0.0",
"@types/istanbul-reports": "^1.1.1",
"@types/yargs": "^12.0.9"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-types/src/Config.ts
Expand Up @@ -6,6 +6,7 @@
*/

import {Arguments} from 'yargs';
import {ReportOptions} from 'istanbul-reports';

export type Path = string;

Expand Down Expand Up @@ -296,7 +297,7 @@ export type GlobalConfig = {
| undefined;
coverageDirectory: string;
coveragePathIgnorePatterns?: Array<string>;
coverageReporters: Array<string>;
coverageReporters: Array<keyof ReportOptions>;
coverageThreshold: CoverageThreshold;
detectLeaks: boolean;
detectOpenHandles: boolean;
Expand Down
12 changes: 8 additions & 4 deletions scripts/mapCoverage.js
Expand Up @@ -25,12 +25,14 @@
* produce a full coverage report.
*/

const createReporter = require('istanbul-api').createReporter;
const istanbulReport = require('istanbul-lib-report');
const istanbulReports = require('istanbul-reports');
const istanbulCoverage = require('istanbul-lib-coverage');
const coverage = require('../coverage/coverage-final.json');

const map = istanbulCoverage.createCoverageMap();
const reporter = createReporter();

const context = istanbulReport.createContext();

const mapFileCoverage = fileCoverage => {
fileCoverage.path = fileCoverage.path.replace(
Expand All @@ -44,5 +46,7 @@ Object.keys(coverage).forEach(filename =>
map.addFileCoverage(mapFileCoverage(coverage[filename]))
);

reporter.addAll(['json', 'lcov', 'text']);
reporter.write(map);
const tree = istanbulReport.summarizers.pkg(map);
['json', 'lcov', 'text'].forEach(reporter =>
tree.visit(istanbulReports.create(reporter, {}), context)
);
74 changes: 18 additions & 56 deletions yarn.lock
Expand Up @@ -1749,6 +1749,13 @@
"@types/istanbul-lib-coverage" "*"
source-map "^0.6.1"

"@types/istanbul-lib-report@*", "@types/istanbul-lib-report@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-report/-/istanbul-lib-report-1.1.0.tgz#79e9b463f947e98dcc82272da51b908fc93e8aea"
integrity sha512-nW5QuzmMhr7fHPijtaGOemFFI8Ctrxb/dIXgouSlKmWT16RxWlGLEX/nGghIBOReKe9hPFZXoNh338nFQk2xcA==
dependencies:
"@types/istanbul-lib-coverage" "*"

"@types/istanbul-lib-source-maps@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.2.1.tgz#c6db98b8b9f0b5aea000f7a8922cc075a85eda9f"
Expand All @@ -1757,6 +1764,14 @@
"@types/istanbul-lib-coverage" "*"
source-map "^0.6.1"

"@types/istanbul-reports@^1.1.0", "@types/istanbul-reports@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-1.1.1.tgz#7a8cbf6a406f36c8add871625b278eaf0b0d255a"
integrity sha512-UpYjBi8xefVChsCoBpKShdxTllC9pwISirfoZsUa2AAdQg/Jd2KQGtSbw+ya7GPo7x/wAPlH6JBhKhAsXUEZNA==
dependencies:
"@types/istanbul-lib-coverage" "*"
"@types/istanbul-lib-report" "*"

"@types/jest@*", "@types/jest@24.0.2":
version "24.0.2"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.2.tgz#a10ad017ee020b2dfa97655323dbf1f38f14f588"
Expand Down Expand Up @@ -2354,13 +2369,6 @@ anymatch@^2.0.0:
micromatch "^3.1.4"
normalize-path "^2.1.1"

append-transform@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-1.0.0.tgz#046a52ae582a228bd72f58acfbe2967c678759ab"
integrity sha512-P009oYkeHyU742iSZJzZZywj4QRJdnTWffaKuJQLablCZ1uz6/cW4yaRgcDaoQ+uwOxxnt0gRUcwfsNP2ri0gw==
dependencies:
default-require-extensions "^2.0.0"

aproba@^1.0.3, aproba@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
Expand Down Expand Up @@ -3787,11 +3795,6 @@ compare-func@^1.3.1:
array-ify "^1.0.0"
dot-prop "^3.0.0"

compare-versions@^3.2.1:
version "3.4.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.4.0.tgz#e0747df5c9cb7f054d6d3dc3e1dbc444f9e92b26"
integrity sha512-tK69D7oNXXqUW3ZNo/z7NXTEz22TCF0pTE+YF9cxvaAM9XnkLo1fV621xCLrRR6aevJlKxExkss0vWqUCUpqdg==

component-bind@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1"
Expand Down Expand Up @@ -4470,13 +4473,6 @@ deepmerge@^2.0.1, deepmerge@^2.1.1:
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
integrity sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==

default-require-extensions@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-2.0.0.tgz#f5f8fbb18a7d6d50b21f641f649ebb522cfe24f7"
integrity sha1-9fj7sYp9bVCyH2QfZJ67Uiz+JPc=
dependencies:
strip-bom "^3.0.0"

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down Expand Up @@ -5856,14 +5852,6 @@ filenamify@^2.0.0:
strip-outer "^1.0.0"
trim-repeated "^1.0.0"

fileset@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/fileset/-/fileset-2.0.3.tgz#8e7548a96d3cc2327ee5e674168723a333bba2a0"
integrity sha1-jnVIqW08wjJ+5eZ0FocjozO7oqA=
dependencies:
glob "^7.0.3"
minimatch "^3.0.3"

filesize@3.5.11:
version "3.5.11"
resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.5.11.tgz#1919326749433bb3cf77368bd158caabcc19e9ee"
Expand Down Expand Up @@ -7553,38 +7541,12 @@ isstream@~0.1.2:
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=

istanbul-api@^2.0.8, istanbul-api@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/istanbul-api/-/istanbul-api-2.1.1.tgz#194b773f6d9cbc99a9258446848b0f988951c4d0"
integrity sha512-kVmYrehiwyeBAk/wE71tW6emzLiHGjYIiDrc8sfyty4F8M02/lrgXSm+R1kXysmF20zArvmZXjlE/mg24TVPJw==
dependencies:
async "^2.6.1"
compare-versions "^3.2.1"
fileset "^2.0.3"
istanbul-lib-coverage "^2.0.3"
istanbul-lib-hook "^2.0.3"
istanbul-lib-instrument "^3.1.0"
istanbul-lib-report "^2.0.4"
istanbul-lib-source-maps "^3.0.2"
istanbul-reports "^2.1.1"
js-yaml "^3.12.0"
make-dir "^1.3.0"
minimatch "^3.0.4"
once "^1.4.0"

istanbul-lib-coverage@^2.0.2, istanbul-lib-coverage@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#0b891e5ad42312c2b9488554f603795f9a2211ba"
integrity sha512-dKWuzRGCs4G+67VfW9pBFFz2Jpi4vSp/k7zBcJ888ofV5Mi1g5CUML5GvMvV6u9Cjybftu+E8Cgp+k0dI1E5lw==

istanbul-lib-hook@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/istanbul-lib-hook/-/istanbul-lib-hook-2.0.3.tgz#e0e581e461c611be5d0e5ef31c5f0109759916fb"
integrity sha512-CLmEqwEhuCYtGcpNVJjLV1DQyVnIqavMLFHV/DP+np/g3qvdxu3gsPqYoJMXm15sN84xOlckFB3VNvRbf5yEgA==
dependencies:
append-transform "^1.0.0"

istanbul-lib-instrument@^3.0.0, istanbul-lib-instrument@^3.0.1, istanbul-lib-instrument@^3.1.0:
istanbul-lib-instrument@^3.0.0, istanbul-lib-instrument@^3.0.1:
version "3.1.0"
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-3.1.0.tgz#a2b5484a7d445f1f311e93190813fa56dfb62971"
integrity sha512-ooVllVGT38HIk8MxDj/OIHXSYvH+1tq/Vb38s8ixt9GoJadXska4WkGY+0wkmtYCZNYtaARniH/DixUGGLZ0uA==
Expand All @@ -7606,7 +7568,7 @@ istanbul-lib-report@^2.0.4:
make-dir "^1.3.0"
supports-color "^6.0.0"

istanbul-lib-source-maps@^3.0.1, istanbul-lib-source-maps@^3.0.2:
istanbul-lib-source-maps@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/istanbul-lib-source-maps/-/istanbul-lib-source-maps-3.0.2.tgz#f1e817229a9146e8424a28e5d69ba220fda34156"
integrity sha512-JX4v0CiKTGp9fZPmoxpu9YEkPbEqCqBbO3403VabKjH+NRXo72HafD5UgnjTEqHL2SAjaZK1XDuDOkn6I5QVfQ==
Expand Down Expand Up @@ -8920,7 +8882,7 @@ minimatch@3.0.3:
dependencies:
brace-expansion "^1.0.0"

minimatch@3.0.4, minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4, minimatch@~3.0.2:
minimatch@3.0.4, minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.4, minimatch@~3.0.2:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
Expand Down

0 comments on commit f3e3d9f

Please sign in to comment.