Skip to content

Commit 2bc190f

Browse files
authored
fix: Delay checking for __coverage__ until helpers run because __coverage__ is undefined when Jest starts (#910)
* fix: Delay checking for __coverage__ until helpers run because __coverage__ is undefined when Jest starts Re: temporal-community/temporal-pendulum#21 * make hasCoverageGlobal() private
1 parent cb10295 commit 2bc190f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/nyc-test-coverage/src/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import libCoverage from 'istanbul-lib-coverage';
55
// Pull `webpack.Configuration` type without needing to import Webpack
66
type WebpackConfigType = ReturnType<NonNullable<BundleOptions['webpackConfigHook']>>;
77

8-
// Check if running through nyc or some other Istanbul-based tool.
9-
// If not, any `workflowCoverage()` tools are a no-op.
10-
const hasCoverageGlobal = '__coverage__' in global;
11-
128
export class WorkflowCoverage {
139
coverageMap = libCoverage.createCoverageMap();
1410

11+
// Check if running through nyc or some other Istanbul-based tool.
12+
// If not, any `workflowCoverage()` tools are a no-op.
13+
private hasCoverageGlobal() {
14+
return '__coverage__' in global;
15+
}
16+
1517
/**
1618
* Add all necessary coverage-specific logic to Worker config:
1719
* interceptors, sinks, and Webpack config hook.
@@ -23,7 +25,7 @@ export class WorkflowCoverage {
2325
throw new TypeError('Cannot automatically instrument coverage without specifying `workflowsPath`');
2426
}
2527

26-
if (!hasCoverageGlobal) {
28+
if (!this.hasCoverageGlobal()) {
2729
return workerOptions;
2830
}
2931

@@ -67,7 +69,7 @@ export class WorkflowCoverage {
6769
throw new TypeError('Cannot automatically instrument coverage without specifying `workflowsPath`');
6870
}
6971

70-
if (!hasCoverageGlobal) {
72+
if (!this.hasCoverageGlobal()) {
7173
return bundleOptions;
7274
}
7375

@@ -101,7 +103,7 @@ export class WorkflowCoverage {
101103
);
102104
}
103105

104-
if (!hasCoverageGlobal) {
106+
if (!this.hasCoverageGlobal()) {
105107
return workerOptions;
106108
}
107109

@@ -142,7 +144,7 @@ export class WorkflowCoverage {
142144
* code using istanbul-instrumenter-loader
143145
*/
144146
addInstrumenterRule(workflowsPath: string, config: WebpackConfigType): WebpackConfigType {
145-
if (!hasCoverageGlobal) {
147+
if (!this.hasCoverageGlobal()) {
146148
return config;
147149
}
148150

@@ -169,7 +171,7 @@ export class WorkflowCoverage {
169171
* map data `global.__coverage__`.
170172
*/
171173
mergeIntoGlobalCoverage(): void {
172-
if (!hasCoverageGlobal) {
174+
if (!this.hasCoverageGlobal()) {
173175
return;
174176
}
175177

0 commit comments

Comments
 (0)