@vitest/coverage-istanbul 0.29.7 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ const COVERAGE_STORE_KEY = "__VITEST_COVERAGE__";
2
+
3
+ export { COVERAGE_STORE_KEY as C };
package/dist/index.d.ts CHANGED
@@ -1,234 +1,14 @@
1
- import { CoverageProvider, Vitest, AfterSuiteRunMeta, ReportContext, ResolvedCoverageOptions } from 'vitest';
2
- import { BaseCoverageProvider } from 'vitest/coverage';
3
- import { CoverageMap } from 'istanbul-lib-coverage';
4
- import { Instrumenter } from 'istanbul-lib-instrument';
5
-
6
- interface RollupError extends RollupLogProps {
7
- parserError?: Error;
8
- stack?: string;
9
- watchFiles?: string[];
10
- }
11
-
12
- interface RollupWarning extends RollupLogProps {
13
- chunkName?: string;
14
- cycle?: string[];
15
- exportName?: string;
16
- exporter?: string;
17
- guess?: string;
18
- importer?: string;
19
- missing?: string;
20
- modules?: string[];
21
- names?: string[];
22
- reexporter?: string;
23
- source?: string;
24
- sources?: string[];
25
- }
26
-
27
- interface RollupLogProps {
28
- code?: string;
29
- frame?: string;
30
- hook?: string;
31
- id?: string;
32
- loc?: {
33
- column: number;
34
- file?: string;
35
- line: number;
36
- };
37
- message: string;
38
- name?: string;
39
- plugin?: string;
40
- pluginCode?: string;
41
- pos?: number;
42
- url?: string;
43
- }
44
-
45
- interface SourceMap {
46
- file: string;
47
- mappings: string;
48
- names: string[];
49
- sources: string[];
50
- sourcesContent: string[];
51
- version: number;
52
- toString(): string;
53
- toUrl(): string;
54
- }
55
-
56
- type PartialNull<T> = {
57
- [P in keyof T]: T[P] | null;
58
- };
59
-
60
- interface ModuleOptions {
61
- meta: CustomPluginOptions;
62
- moduleSideEffects: boolean | 'no-treeshake';
63
- syntheticNamedExports: boolean | string;
64
- }
65
-
66
- interface PluginCache {
67
- delete(id: string): boolean;
68
- get<T = any>(id: string): T;
69
- has(id: string): boolean;
70
- set<T = any>(id: string, value: T): void;
71
- }
72
-
73
- interface MinimalPluginContext {
74
- meta: PluginContextMeta;
75
- }
76
-
77
- interface EmittedAsset {
78
- fileName?: string;
79
- name?: string;
80
- source?: string | Uint8Array;
81
- type: 'asset';
82
- }
83
-
84
- interface EmittedChunk {
85
- fileName?: string;
86
- id: string;
87
- implicitlyLoadedAfterOneOf?: string[];
88
- importer?: string;
89
- name?: string;
90
- preserveSignature?: PreserveEntrySignaturesOption;
91
- type: 'chunk';
92
- }
93
-
94
- type EmittedFile = EmittedAsset | EmittedChunk;
95
-
96
- type EmitAsset = (name: string, source?: string | Uint8Array) => string;
97
-
98
- type EmitChunk = (id: string, options?: { name?: string }) => string;
99
-
100
- type EmitFile = (emittedFile: EmittedFile) => string;
101
-
102
- interface ModuleInfo extends ModuleOptions {
103
- ast: AcornNode | null;
104
- code: string | null;
105
- dynamicImporters: readonly string[];
106
- dynamicallyImportedIdResolutions: readonly ResolvedId[];
107
- dynamicallyImportedIds: readonly string[];
108
- hasDefaultExport: boolean | null;
109
- /** @deprecated Use `moduleSideEffects` instead */
110
- hasModuleSideEffects: boolean | 'no-treeshake';
111
- id: string;
112
- implicitlyLoadedAfterOneOf: readonly string[];
113
- implicitlyLoadedBefore: readonly string[];
114
- importedIdResolutions: readonly ResolvedId[];
115
- importedIds: readonly string[];
116
- importers: readonly string[];
117
- isEntry: boolean;
118
- isExternal: boolean;
119
- isIncluded: boolean | null;
120
- }
121
-
122
- type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
123
-
124
- interface CustomPluginOptions {
125
- [plugin: string]: any;
126
- }
127
-
128
- interface PluginContext extends MinimalPluginContext {
129
- addWatchFile: (id: string) => void;
130
- cache: PluginCache;
131
- /** @deprecated Use `this.emitFile` instead */
132
- emitAsset: EmitAsset;
133
- /** @deprecated Use `this.emitFile` instead */
134
- emitChunk: EmitChunk;
135
- emitFile: EmitFile;
136
- error: (err: RollupError | string, pos?: number | { column: number; line: number }) => never;
137
- /** @deprecated Use `this.getFileName` instead */
138
- getAssetFileName: (assetReferenceId: string) => string;
139
- /** @deprecated Use `this.getFileName` instead */
140
- getChunkFileName: (chunkReferenceId: string) => string;
141
- getFileName: (fileReferenceId: string) => string;
142
- getModuleIds: () => IterableIterator<string>;
143
- getModuleInfo: GetModuleInfo;
144
- getWatchFiles: () => string[];
145
- /** @deprecated Use `this.resolve` instead */
146
- isExternal: IsExternal;
147
- load: (
148
- options: { id: string; resolveDependencies?: boolean } & Partial<PartialNull<ModuleOptions>>
149
- ) => Promise<ModuleInfo>;
150
- /** @deprecated Use `this.getModuleIds` instead */
151
- moduleIds: IterableIterator<string>;
152
- parse: (input: string, options?: any) => AcornNode;
153
- resolve: (
154
- source: string,
155
- importer?: string,
156
- options?: { custom?: CustomPluginOptions; isEntry?: boolean; skipSelf?: boolean }
157
- ) => Promise<ResolvedId | null>;
158
- /** @deprecated Use `this.resolve` instead */
159
- resolveId: (source: string, importer?: string) => Promise<string | null>;
160
- setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void;
161
- warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void;
162
- }
163
-
164
- interface PluginContextMeta {
165
- rollupVersion: string;
166
- watchMode: boolean;
167
- }
168
-
169
- interface ResolvedId extends ModuleOptions {
170
- external: boolean | 'absolute';
171
- id: string;
172
- }
173
-
174
- type IsExternal = (
175
- source: string,
176
- importer: string | undefined,
177
- isResolved: boolean
178
- ) => boolean;
179
-
180
- interface TransformPluginContext extends PluginContext {
181
- getCombinedSourcemap: () => SourceMap;
182
- }
183
- type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
184
-
185
- interface AcornNode {
186
- end: number;
187
- start: number;
188
- type: string;
189
- }
190
-
191
- type Options = ResolvedCoverageOptions<'istanbul'>;
192
- type Threshold = 'lines' | 'functions' | 'statements' | 'branches';
193
- interface TestExclude {
194
- new (opts: {
195
- cwd?: string | string[];
196
- include?: string | string[];
197
- exclude?: string | string[];
198
- extension?: string | string[];
199
- excludeNodeModules?: boolean;
200
- }): {
201
- shouldInstrument(filePath: string): boolean;
202
- glob(cwd: string): Promise<string[]>;
203
- };
204
- }
205
- declare class IstanbulCoverageProvider extends BaseCoverageProvider implements CoverageProvider {
206
- name: string;
207
- ctx: Vitest;
208
- options: Options;
209
- instrumenter: Instrumenter;
210
- testExclude: InstanceType<TestExclude>;
211
- /**
212
- * Coverage objects collected from workers.
213
- * Some istanbul utilizers write these into file system instead of storing in memory.
214
- * If storing in memory causes issues, we can simply write these into fs in `onAfterSuiteRun`
215
- * and read them back when merging coverage objects in `onAfterAllFilesRun`.
216
- */
217
- coverages: any[];
218
- initialize(ctx: Vitest): void;
219
- resolveOptions(): Options;
220
- onFileTransform(sourceCode: string, id: string, pluginCtx: TransformPluginContext): {
221
- code: string;
222
- map: any;
223
- } | undefined;
224
- onAfterSuiteRun({ coverage }: AfterSuiteRunMeta): void;
225
- clean(clean?: boolean): Promise<void>;
226
- reportCoverage({ allTestsRun }?: ReportContext): Promise<void>;
227
- checkThresholds(coverageMap: CoverageMap, thresholds: Record<Threshold, number | undefined>): void;
228
- includeUntestedFiles(coverageMap: CoverageMap): Promise<void>;
229
- }
1
+ import { IstanbulCoverageProvider } from './provider.js';
2
+ import 'vitest';
3
+ import 'vitest/coverage';
4
+ import 'istanbul-lib-coverage';
5
+ import 'istanbul-lib-instrument';
230
6
 
231
7
  declare function getProvider(): Promise<IstanbulCoverageProvider>;
232
8
  declare function takeCoverage(): any;
9
+ declare const _default: {
10
+ getProvider: typeof getProvider;
11
+ takeCoverage: typeof takeCoverage;
12
+ };
233
13
 
234
- export { getProvider, takeCoverage };
14
+ export { _default as default, getProvider, takeCoverage };
package/dist/index.js CHANGED
@@ -1 +1,18 @@
1
- export { g as getProvider, t as takeCoverage } from './index-f1f55bac.js';
1
+ import { C as COVERAGE_STORE_KEY } from './constants-758a8358.js';
2
+
3
+ async function getProvider() {
4
+ const providerPath = "./provider.js";
5
+ const { IstanbulCoverageProvider } = await import(providerPath);
6
+ return new IstanbulCoverageProvider();
7
+ }
8
+ function takeCoverage() {
9
+ const coverage = globalThis[COVERAGE_STORE_KEY];
10
+ globalThis[COVERAGE_STORE_KEY] = {};
11
+ return coverage;
12
+ }
13
+ var index = {
14
+ getProvider,
15
+ takeCoverage
16
+ };
17
+
18
+ export { index as default, getProvider, takeCoverage };
@@ -0,0 +1,212 @@
1
+ import { CoverageProvider, Vitest, AfterSuiteRunMeta, ReportContext, ResolvedCoverageOptions } from 'vitest';
2
+ import { BaseCoverageProvider } from 'vitest/coverage';
3
+ import { CoverageMap } from 'istanbul-lib-coverage';
4
+ import { Instrumenter } from 'istanbul-lib-instrument';
5
+
6
+ type PartialNull<T> = {
7
+ [P in keyof T]: T[P] | null;
8
+ };
9
+
10
+ interface RollupError extends RollupLog {
11
+ name?: string;
12
+ stack?: string;
13
+ watchFiles?: string[];
14
+ }
15
+
16
+ type RollupWarning = RollupLog;
17
+
18
+ interface RollupLog {
19
+ binding?: string;
20
+ cause?: unknown;
21
+ code?: string;
22
+ exporter?: string;
23
+ frame?: string;
24
+ hook?: string;
25
+ id?: string;
26
+ ids?: string[];
27
+ loc?: {
28
+ column: number;
29
+ file?: string;
30
+ line: number;
31
+ };
32
+ message: string;
33
+ names?: string[];
34
+ plugin?: string;
35
+ pluginCode?: string;
36
+ pos?: number;
37
+ reexporter?: string;
38
+ stack?: string;
39
+ url?: string;
40
+ }
41
+
42
+ interface SourceMap {
43
+ file: string;
44
+ mappings: string;
45
+ names: string[];
46
+ sources: string[];
47
+ sourcesContent: (string | null)[];
48
+ version: number;
49
+ toString(): string;
50
+ toUrl(): string;
51
+ }
52
+
53
+ interface ModuleOptions {
54
+ assertions: Record<string, string>;
55
+ meta: CustomPluginOptions;
56
+ moduleSideEffects: boolean | 'no-treeshake';
57
+ syntheticNamedExports: boolean | string;
58
+ }
59
+
60
+ interface PluginCache {
61
+ delete(id: string): boolean;
62
+ get<T = any>(id: string): T;
63
+ has(id: string): boolean;
64
+ set<T = any>(id: string, value: T): void;
65
+ }
66
+
67
+ interface MinimalPluginContext {
68
+ meta: PluginContextMeta;
69
+ }
70
+
71
+ interface EmittedAsset {
72
+ fileName?: string;
73
+ name?: string;
74
+ needsCodeReference?: boolean;
75
+ source?: string | Uint8Array;
76
+ type: 'asset';
77
+ }
78
+
79
+ interface EmittedChunk {
80
+ fileName?: string;
81
+ id: string;
82
+ implicitlyLoadedAfterOneOf?: string[];
83
+ importer?: string;
84
+ name?: string;
85
+ preserveSignature?: PreserveEntrySignaturesOption;
86
+ type: 'chunk';
87
+ }
88
+
89
+ type EmittedFile = EmittedAsset | EmittedChunk;
90
+
91
+ type EmitFile = (emittedFile: EmittedFile) => string;
92
+
93
+ interface ModuleInfo extends ModuleOptions {
94
+ ast: AcornNode | null;
95
+ code: string | null;
96
+ dynamicImporters: readonly string[];
97
+ dynamicallyImportedIdResolutions: readonly ResolvedId[];
98
+ dynamicallyImportedIds: readonly string[];
99
+ exportedBindings: Record<string, string[]> | null;
100
+ exports: string[] | null;
101
+ hasDefaultExport: boolean | null;
102
+ /** @deprecated Use `moduleSideEffects` instead */
103
+ hasModuleSideEffects: boolean | 'no-treeshake';
104
+ id: string;
105
+ implicitlyLoadedAfterOneOf: readonly string[];
106
+ implicitlyLoadedBefore: readonly string[];
107
+ importedIdResolutions: readonly ResolvedId[];
108
+ importedIds: readonly string[];
109
+ importers: readonly string[];
110
+ isEntry: boolean;
111
+ isExternal: boolean;
112
+ isIncluded: boolean | null;
113
+ }
114
+
115
+ type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
116
+
117
+ interface CustomPluginOptions {
118
+ [plugin: string]: any;
119
+ }
120
+
121
+ interface PluginContext extends MinimalPluginContext {
122
+ addWatchFile: (id: string) => void;
123
+ cache: PluginCache;
124
+ emitFile: EmitFile;
125
+ error: (error: RollupError | string, pos?: number | { column: number; line: number }) => never;
126
+ getFileName: (fileReferenceId: string) => string;
127
+ getModuleIds: () => IterableIterator<string>;
128
+ getModuleInfo: GetModuleInfo;
129
+ getWatchFiles: () => string[];
130
+ load: (
131
+ options: { id: string; resolveDependencies?: boolean } & Partial<PartialNull<ModuleOptions>>
132
+ ) => Promise<ModuleInfo>;
133
+ /** @deprecated Use `this.getModuleIds` instead */
134
+ moduleIds: IterableIterator<string>;
135
+ parse: (input: string, options?: any) => AcornNode;
136
+ resolve: (
137
+ source: string,
138
+ importer?: string,
139
+ options?: {
140
+ assertions?: Record<string, string>;
141
+ custom?: CustomPluginOptions;
142
+ isEntry?: boolean;
143
+ skipSelf?: boolean;
144
+ }
145
+ ) => Promise<ResolvedId | null>;
146
+ setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void;
147
+ warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void;
148
+ }
149
+
150
+ interface PluginContextMeta {
151
+ rollupVersion: string;
152
+ watchMode: boolean;
153
+ }
154
+
155
+ interface ResolvedId extends ModuleOptions {
156
+ external: boolean | 'absolute';
157
+ id: string;
158
+ resolvedBy: string;
159
+ }
160
+
161
+ interface TransformPluginContext extends PluginContext {
162
+ getCombinedSourcemap: () => SourceMap;
163
+ }
164
+ type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
165
+
166
+ interface AcornNode {
167
+ end: number;
168
+ start: number;
169
+ type: string;
170
+ }
171
+
172
+ type Options = ResolvedCoverageOptions<'istanbul'>;
173
+ type Threshold = 'lines' | 'functions' | 'statements' | 'branches';
174
+ interface TestExclude {
175
+ new (opts: {
176
+ cwd?: string | string[];
177
+ include?: string | string[];
178
+ exclude?: string | string[];
179
+ extension?: string | string[];
180
+ excludeNodeModules?: boolean;
181
+ }): {
182
+ shouldInstrument(filePath: string): boolean;
183
+ glob(cwd: string): Promise<string[]>;
184
+ };
185
+ }
186
+ declare class IstanbulCoverageProvider extends BaseCoverageProvider implements CoverageProvider {
187
+ name: string;
188
+ ctx: Vitest;
189
+ options: Options;
190
+ instrumenter: Instrumenter;
191
+ testExclude: InstanceType<TestExclude>;
192
+ /**
193
+ * Coverage objects collected from workers.
194
+ * Some istanbul utilizers write these into file system instead of storing in memory.
195
+ * If storing in memory causes issues, we can simply write these into fs in `onAfterSuiteRun`
196
+ * and read them back when merging coverage objects in `onAfterAllFilesRun`.
197
+ */
198
+ coverages: any[];
199
+ initialize(ctx: Vitest): void;
200
+ resolveOptions(): Options;
201
+ onFileTransform(sourceCode: string, id: string, pluginCtx: TransformPluginContext): {
202
+ code: string;
203
+ map: any;
204
+ } | undefined;
205
+ onAfterSuiteRun({ coverage }: AfterSuiteRunMeta): void;
206
+ clean(clean?: boolean): Promise<void>;
207
+ reportCoverage({ allTestsRun }?: ReportContext): Promise<void>;
208
+ checkThresholds(coverageMap: CoverageMap, thresholds: Record<Threshold, number | undefined>): void;
209
+ includeUntestedFiles(coverageMap: CoverageMap): Promise<void>;
210
+ }
211
+
212
+ export { IstanbulCoverageProvider };
@@ -7,7 +7,7 @@ import libCoverage from 'istanbul-lib-coverage';
7
7
  import libSourceMaps from 'istanbul-lib-source-maps';
8
8
  import { createInstrumenter } from 'istanbul-lib-instrument';
9
9
  import _TestExclude from 'test-exclude';
10
- import { C as COVERAGE_STORE_KEY } from './index-f1f55bac.js';
10
+ import { C as COVERAGE_STORE_KEY } from './constants-758a8358.js';
11
11
 
12
12
  function normalizeWindowsPath(input = "") {
13
13
  if (!input || !input.includes("\\")) {
@@ -120,6 +120,12 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
120
120
  constructor() {
121
121
  super(...arguments);
122
122
  this.name = "istanbul";
123
+ /**
124
+ * Coverage objects collected from workers.
125
+ * Some istanbul utilizers write these into file system instead of storing in memory.
126
+ * If storing in memory causes issues, we can simply write these into fs in `onAfterSuiteRun`
127
+ * and read them back when merging coverage objects in `onAfterAllFilesRun`.
128
+ */
123
129
  this.coverages = [];
124
130
  }
125
131
  initialize(ctx) {
@@ -127,7 +133,9 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
127
133
  this.ctx = ctx;
128
134
  this.options = {
129
135
  ...coverageConfigDefaults,
136
+ // User's options
130
137
  ...config,
138
+ // Resolved fields
131
139
  provider: "istanbul",
132
140
  reportsDirectory: resolve(ctx.config.root, config.reportsDirectory || coverageConfigDefaults.reportsDirectory),
133
141
  reporter: this.resolveReporters(config.reporter || coverageConfigDefaults.reporter)
@@ -138,6 +146,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
138
146
  esModules: true,
139
147
  compact: false,
140
148
  coverageVariable: COVERAGE_STORE_KEY,
149
+ // @ts-expect-error missing type
141
150
  coverageGlobalScope: "globalThis",
142
151
  coverageGlobalScopeFunc: false,
143
152
  ignoreClassMethods: this.options.ignoreClassMethods
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/coverage-istanbul",
3
3
  "type": "module",
4
- "version": "0.29.7",
4
+ "version": "0.30.0",
5
5
  "description": "Istanbul coverage provider for Vitest",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "dist"
38
38
  ],
39
39
  "peerDependencies": {
40
- "vitest": ">=0.28.0 <1"
40
+ "vitest": ">=0.30.0 <1"
41
41
  },
42
42
  "dependencies": {
43
43
  "istanbul-lib-coverage": "^3.2.0",
@@ -54,7 +54,7 @@
54
54
  "@types/istanbul-lib-source-maps": "^4.0.1",
55
55
  "@types/istanbul-reports": "^3.0.1",
56
56
  "pathe": "^1.1.0",
57
- "vitest": "0.29.7"
57
+ "vitest": "0.30.0"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "rimraf dist && rollup -c",
@@ -1,13 +0,0 @@
1
- const COVERAGE_STORE_KEY = "__VITEST_COVERAGE__";
2
-
3
- async function getProvider() {
4
- const { IstanbulCoverageProvider } = await import('./provider-bca6bd2d.js');
5
- return new IstanbulCoverageProvider();
6
- }
7
- function takeCoverage() {
8
- const coverage = globalThis[COVERAGE_STORE_KEY];
9
- globalThis[COVERAGE_STORE_KEY] = {};
10
- return coverage;
11
- }
12
-
13
- export { COVERAGE_STORE_KEY as C, getProvider as g, takeCoverage as t };