Skip to content

Commit f3e3d9f

Browse files
coreyfarrellSimenB
authored andcommitted
Stop using istanbul-api (#8294)
1 parent 65b48a7 commit f3e3d9f

File tree

10 files changed

+53
-103
lines changed

10 files changed

+53
-103
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

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

2930
### Performance
3031

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
"glob": "^7.1.1",
4444
"graceful-fs": "^4.1.15",
4545
"isbinaryfile": "^4.0.0",
46-
"istanbul-api": "^2.0.8",
4746
"istanbul-lib-coverage": "^2.0.2",
47+
"istanbul-lib-report": "^2.0.4",
48+
"istanbul-reports": "^2.1.1",
4849
"jest-junit": "^6.2.1",
4950
"jest-silent-reporter": "^0.1.2",
5051
"jest-snapshot-serializer-raw": "^1.1.0",

packages/jest-reporters/istanbul-api.d.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/jest-reporters/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
"chalk": "^2.0.1",
1313
"exit": "^0.1.2",
1414
"glob": "^7.1.2",
15-
"istanbul-api": "^2.1.1",
1615
"istanbul-lib-coverage": "^2.0.2",
1716
"istanbul-lib-instrument": "^3.0.1",
17+
"istanbul-lib-report": "^2.0.4",
1818
"istanbul-lib-source-maps": "^3.0.1",
19+
"istanbul-reports": "^2.1.1",
1920
"jest-haste-map": "^24.7.1",
2021
"jest-resolve": "^24.7.1",
2122
"jest-runtime": "^24.7.1",
@@ -31,7 +32,9 @@
3132
"@types/glob": "^7.1.1",
3233
"@types/istanbul-lib-coverage": "^2.0.0",
3334
"@types/istanbul-lib-instrument": "^1.7.2",
35+
"@types/istanbul-lib-report": "^1.1.0",
3436
"@types/istanbul-lib-source-maps": "^1.2.1",
37+
"@types/istanbul-reports": "^1.1.0",
3538
"@types/node-notifier": "^5.4.0",
3639
"@types/slash": "^2.0.0",
3740
"@types/string-length": "^2.0.0",

packages/jest-reporters/src/__tests__/coverage_reporter.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
jest.mock('istanbul-lib-source-maps').mock('istanbul-api');
8+
jest
9+
.mock('istanbul-lib-source-maps')
10+
.mock('istanbul-lib-report', () => ({
11+
createContext: jest.fn(),
12+
summarizers: {pkg: jest.fn(() => ({visit: jest.fn()}))},
13+
}))
14+
.mock('istanbul-reports');
915

1016
let libCoverage;
1117
let libSourceMaps;
1218
let CoverageReporter;
13-
let istanbulApi;
1419

1520
import path from 'path';
1621
import mock from 'mock-fs';
1722

1823
beforeEach(() => {
19-
istanbulApi = require('istanbul-api');
20-
istanbulApi.createReporter = jest.fn(() => ({
21-
addAll: jest.fn(),
22-
write: jest.fn(),
23-
}));
24-
2524
CoverageReporter = require('../coverage_reporter').default;
2625
libCoverage = require('istanbul-lib-coverage');
2726
libSourceMaps = require('istanbul-lib-source-maps');

packages/jest-reporters/src/coverage_reporter.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
// TODO: Remove this
9-
/// <reference path="../istanbul-api.d.ts" />
10-
118
import path from 'path';
129
import {Config} from '@jest/types';
1310
import {AggregatedResult, TestResult} from '@jest/test-result';
1411
import {clearLine, isInteractive} from 'jest-util';
15-
import {createReporter} from 'istanbul-api';
12+
import istanbulReport from 'istanbul-lib-report';
13+
import istanbulReports from 'istanbul-reports';
1614
import chalk from 'chalk';
1715
import istanbulCoverage, {
1816
CoverageMap,
@@ -88,20 +86,21 @@ export default class CoverageReporter extends BaseReporter {
8886
this._coverageMap,
8987
);
9088

91-
const reporter = createReporter();
9289
try {
93-
if (this._globalConfig.coverageDirectory) {
94-
reporter.dir = this._globalConfig.coverageDirectory;
95-
}
96-
90+
const reportContext = istanbulReport.createContext({
91+
dir: this._globalConfig.coverageDirectory,
92+
sourceFinder,
93+
});
9794
const coverageReporters = this._globalConfig.coverageReporters || [];
9895

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

103-
reporter.addAll(coverageReporters);
104-
reporter.write(map, sourceFinder && {sourceFinder});
100+
const tree = istanbulReport.summarizers.pkg(map);
101+
coverageReporters.forEach(reporter => {
102+
tree.visit(istanbulReports.create(reporter, {}), reportContext);
103+
});
105104
aggregatedResults.coverageMap = map;
106105
} catch (e) {
107106
console.error(

packages/jest-types/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"types": "build/index.d.ts",
1515
"dependencies": {
1616
"@types/istanbul-lib-coverage": "^2.0.0",
17+
"@types/istanbul-reports": "^1.1.1",
1718
"@types/yargs": "^12.0.9"
1819
},
1920
"publishConfig": {

packages/jest-types/src/Config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import {Arguments} from 'yargs';
9+
import {ReportOptions} from 'istanbul-reports';
910

1011
export type Path = string;
1112

@@ -296,7 +297,7 @@ export type GlobalConfig = {
296297
| undefined;
297298
coverageDirectory: string;
298299
coveragePathIgnorePatterns?: Array<string>;
299-
coverageReporters: Array<string>;
300+
coverageReporters: Array<keyof ReportOptions>;
300301
coverageThreshold: CoverageThreshold;
301302
detectLeaks: boolean;
302303
detectOpenHandles: boolean;

scripts/mapCoverage.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
* produce a full coverage report.
2626
*/
2727

28-
const createReporter = require('istanbul-api').createReporter;
28+
const istanbulReport = require('istanbul-lib-report');
29+
const istanbulReports = require('istanbul-reports');
2930
const istanbulCoverage = require('istanbul-lib-coverage');
3031
const coverage = require('../coverage/coverage-final.json');
3132

3233
const map = istanbulCoverage.createCoverageMap();
33-
const reporter = createReporter();
34+
35+
const context = istanbulReport.createContext();
3436

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

47-
reporter.addAll(['json', 'lcov', 'text']);
48-
reporter.write(map);
49+
const tree = istanbulReport.summarizers.pkg(map);
50+
['json', 'lcov', 'text'].forEach(reporter =>
51+
tree.visit(istanbulReports.create(reporter, {}), context)
52+
);

yarn.lock

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,13 @@
17491749
"@types/istanbul-lib-coverage" "*"
17501750
source-map "^0.6.1"
17511751

1752+
"@types/istanbul-lib-report@*", "@types/istanbul-lib-report@^1.1.0":
1753+
version "1.1.0"
1754+
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-report/-/istanbul-lib-report-1.1.0.tgz#79e9b463f947e98dcc82272da51b908fc93e8aea"
1755+
integrity sha512-nW5QuzmMhr7fHPijtaGOemFFI8Ctrxb/dIXgouSlKmWT16RxWlGLEX/nGghIBOReKe9hPFZXoNh338nFQk2xcA==
1756+
dependencies:
1757+
"@types/istanbul-lib-coverage" "*"
1758+
17521759
"@types/istanbul-lib-source-maps@^1.2.1":
17531760
version "1.2.1"
17541761
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.2.1.tgz#c6db98b8b9f0b5aea000f7a8922cc075a85eda9f"
@@ -1757,6 +1764,14 @@
17571764
"@types/istanbul-lib-coverage" "*"
17581765
source-map "^0.6.1"
17591766

1767+
"@types/istanbul-reports@^1.1.0", "@types/istanbul-reports@^1.1.1":
1768+
version "1.1.1"
1769+
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-1.1.1.tgz#7a8cbf6a406f36c8add871625b278eaf0b0d255a"
1770+
integrity sha512-UpYjBi8xefVChsCoBpKShdxTllC9pwISirfoZsUa2AAdQg/Jd2KQGtSbw+ya7GPo7x/wAPlH6JBhKhAsXUEZNA==
1771+
dependencies:
1772+
"@types/istanbul-lib-coverage" "*"
1773+
"@types/istanbul-lib-report" "*"
1774+
17601775
"@types/jest@*", "@types/[email protected]":
17611776
version "24.0.2"
17621777
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.2.tgz#a10ad017ee020b2dfa97655323dbf1f38f14f588"
@@ -2354,13 +2369,6 @@ anymatch@^2.0.0:
23542369
micromatch "^3.1.4"
23552370
normalize-path "^2.1.1"
23562371

2357-
append-transform@^1.0.0:
2358-
version "1.0.0"
2359-
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-1.0.0.tgz#046a52ae582a228bd72f58acfbe2967c678759ab"
2360-
integrity sha512-P009oYkeHyU742iSZJzZZywj4QRJdnTWffaKuJQLablCZ1uz6/cW4yaRgcDaoQ+uwOxxnt0gRUcwfsNP2ri0gw==
2361-
dependencies:
2362-
default-require-extensions "^2.0.0"
2363-
23642372
aproba@^1.0.3, aproba@^1.1.1:
23652373
version "1.2.0"
23662374
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
@@ -3787,11 +3795,6 @@ compare-func@^1.3.1:
37873795
array-ify "^1.0.0"
37883796
dot-prop "^3.0.0"
37893797

3790-
compare-versions@^3.2.1:
3791-
version "3.4.0"
3792-
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.4.0.tgz#e0747df5c9cb7f054d6d3dc3e1dbc444f9e92b26"
3793-
integrity sha512-tK69D7oNXXqUW3ZNo/z7NXTEz22TCF0pTE+YF9cxvaAM9XnkLo1fV621xCLrRR6aevJlKxExkss0vWqUCUpqdg==
3794-
37953798
37963799
version "1.0.0"
37973800
resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1"
@@ -4470,13 +4473,6 @@ deepmerge@^2.0.1, deepmerge@^2.1.1:
44704473
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
44714474
integrity sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==
44724475

4473-
default-require-extensions@^2.0.0:
4474-
version "2.0.0"
4475-
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-2.0.0.tgz#f5f8fbb18a7d6d50b21f641f649ebb522cfe24f7"
4476-
integrity sha1-9fj7sYp9bVCyH2QfZJ67Uiz+JPc=
4477-
dependencies:
4478-
strip-bom "^3.0.0"
4479-
44804476
defaults@^1.0.3:
44814477
version "1.0.3"
44824478
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
@@ -5856,14 +5852,6 @@ filenamify@^2.0.0:
58565852
strip-outer "^1.0.0"
58575853
trim-repeated "^1.0.0"
58585854

5859-
fileset@^2.0.3:
5860-
version "2.0.3"
5861-
resolved "https://registry.yarnpkg.com/fileset/-/fileset-2.0.3.tgz#8e7548a96d3cc2327ee5e674168723a333bba2a0"
5862-
integrity sha1-jnVIqW08wjJ+5eZ0FocjozO7oqA=
5863-
dependencies:
5864-
glob "^7.0.3"
5865-
minimatch "^3.0.3"
5866-
58675855
58685856
version "3.5.11"
58695857
resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.5.11.tgz#1919326749433bb3cf77368bd158caabcc19e9ee"
@@ -7553,38 +7541,12 @@ isstream@~0.1.2:
75537541
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
75547542
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=
75557543

7556-
istanbul-api@^2.0.8, istanbul-api@^2.1.1:
7557-
version "2.1.1"
7558-
resolved "https://registry.yarnpkg.com/istanbul-api/-/istanbul-api-2.1.1.tgz#194b773f6d9cbc99a9258446848b0f988951c4d0"
7559-
integrity sha512-kVmYrehiwyeBAk/wE71tW6emzLiHGjYIiDrc8sfyty4F8M02/lrgXSm+R1kXysmF20zArvmZXjlE/mg24TVPJw==
7560-
dependencies:
7561-
async "^2.6.1"
7562-
compare-versions "^3.2.1"
7563-
fileset "^2.0.3"
7564-
istanbul-lib-coverage "^2.0.3"
7565-
istanbul-lib-hook "^2.0.3"
7566-
istanbul-lib-instrument "^3.1.0"
7567-
istanbul-lib-report "^2.0.4"
7568-
istanbul-lib-source-maps "^3.0.2"
7569-
istanbul-reports "^2.1.1"
7570-
js-yaml "^3.12.0"
7571-
make-dir "^1.3.0"
7572-
minimatch "^3.0.4"
7573-
once "^1.4.0"
7574-
75757544
istanbul-lib-coverage@^2.0.2, istanbul-lib-coverage@^2.0.3:
75767545
version "2.0.3"
75777546
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#0b891e5ad42312c2b9488554f603795f9a2211ba"
75787547
integrity sha512-dKWuzRGCs4G+67VfW9pBFFz2Jpi4vSp/k7zBcJ888ofV5Mi1g5CUML5GvMvV6u9Cjybftu+E8Cgp+k0dI1E5lw==
75797548

7580-
istanbul-lib-hook@^2.0.3:
7581-
version "2.0.3"
7582-
resolved "https://registry.yarnpkg.com/istanbul-lib-hook/-/istanbul-lib-hook-2.0.3.tgz#e0e581e461c611be5d0e5ef31c5f0109759916fb"
7583-
integrity sha512-CLmEqwEhuCYtGcpNVJjLV1DQyVnIqavMLFHV/DP+np/g3qvdxu3gsPqYoJMXm15sN84xOlckFB3VNvRbf5yEgA==
7584-
dependencies:
7585-
append-transform "^1.0.0"
7586-
7587-
istanbul-lib-instrument@^3.0.0, istanbul-lib-instrument@^3.0.1, istanbul-lib-instrument@^3.1.0:
7549+
istanbul-lib-instrument@^3.0.0, istanbul-lib-instrument@^3.0.1:
75887550
version "3.1.0"
75897551
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-3.1.0.tgz#a2b5484a7d445f1f311e93190813fa56dfb62971"
75907552
integrity sha512-ooVllVGT38HIk8MxDj/OIHXSYvH+1tq/Vb38s8ixt9GoJadXska4WkGY+0wkmtYCZNYtaARniH/DixUGGLZ0uA==
@@ -7606,7 +7568,7 @@ istanbul-lib-report@^2.0.4:
76067568
make-dir "^1.3.0"
76077569
supports-color "^6.0.0"
76087570

7609-
istanbul-lib-source-maps@^3.0.1, istanbul-lib-source-maps@^3.0.2:
7571+
istanbul-lib-source-maps@^3.0.1:
76107572
version "3.0.2"
76117573
resolved "https://registry.yarnpkg.com/istanbul-lib-source-maps/-/istanbul-lib-source-maps-3.0.2.tgz#f1e817229a9146e8424a28e5d69ba220fda34156"
76127574
integrity sha512-JX4v0CiKTGp9fZPmoxpu9YEkPbEqCqBbO3403VabKjH+NRXo72HafD5UgnjTEqHL2SAjaZK1XDuDOkn6I5QVfQ==
@@ -8920,7 +8882,7 @@ [email protected]:
89208882
dependencies:
89218883
brace-expansion "^1.0.0"
89228884

8923-
[email protected], minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4, minimatch@~3.0.2:
8885+
[email protected], minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.4, minimatch@~3.0.2:
89248886
version "3.0.4"
89258887
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
89268888
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==

0 commit comments

Comments
 (0)