@vitest/coverage-istanbul 0.27.2 → 0.28.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.
@@ -1,7 +1,7 @@
|
|
1
1
|
const COVERAGE_STORE_KEY = "__VITEST_COVERAGE__";
|
2
2
|
|
3
3
|
async function getProvider() {
|
4
|
-
const { IstanbulCoverageProvider } = await import('./provider-
|
4
|
+
const { IstanbulCoverageProvider } = await import('./provider-e9fe5ea1.js');
|
5
5
|
return new IstanbulCoverageProvider();
|
6
6
|
}
|
7
7
|
function takeCoverage() {
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CoverageProvider, Vitest,
|
1
|
+
import { CoverageProvider, Vitest, AfterSuiteRunMeta, ReportContext, ResolvedCoverageOptions } from 'vitest';
|
2
2
|
import { CoverageMap } from 'istanbul-lib-coverage';
|
3
3
|
import { Instrumenter } from 'istanbul-lib-instrument';
|
4
4
|
|
@@ -187,6 +187,7 @@ interface AcornNode {
|
|
187
187
|
type: string;
|
188
188
|
}
|
189
189
|
|
190
|
+
type Options = ResolvedCoverageOptions<'istanbul'>;
|
190
191
|
type Threshold = 'lines' | 'functions' | 'statements' | 'branches';
|
191
192
|
interface TestExclude {
|
192
193
|
new (opts: {
|
@@ -203,9 +204,7 @@ interface TestExclude {
|
|
203
204
|
declare class IstanbulCoverageProvider implements CoverageProvider {
|
204
205
|
name: string;
|
205
206
|
ctx: Vitest;
|
206
|
-
options:
|
207
|
-
provider: 'istanbul';
|
208
|
-
};
|
207
|
+
options: Options;
|
209
208
|
instrumenter: Instrumenter;
|
210
209
|
testExclude: InstanceType<TestExclude>;
|
211
210
|
/**
|
@@ -216,14 +215,14 @@ declare class IstanbulCoverageProvider implements CoverageProvider {
|
|
216
215
|
*/
|
217
216
|
coverages: any[];
|
218
217
|
initialize(ctx: Vitest): void;
|
219
|
-
resolveOptions():
|
218
|
+
resolveOptions(): Options;
|
220
219
|
onFileTransform(sourceCode: string, id: string, pluginCtx: TransformPluginContext): {
|
221
220
|
code: string;
|
222
221
|
map: any;
|
223
222
|
} | undefined;
|
224
223
|
onAfterSuiteRun({ coverage }: AfterSuiteRunMeta): void;
|
225
224
|
clean(clean?: boolean): Promise<void>;
|
226
|
-
reportCoverage({ allTestsRun }
|
225
|
+
reportCoverage({ allTestsRun }?: ReportContext): Promise<void>;
|
227
226
|
checkThresholds(coverageMap: CoverageMap, thresholds: Record<Threshold, number | undefined>): void;
|
228
227
|
includeUntestedFiles(coverageMap: CoverageMap): Promise<void>;
|
229
228
|
}
|
package/dist/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { g as getProvider, t as takeCoverage } from './index-
|
1
|
+
export { g as getProvider, t as takeCoverage } from './index-2345780c.js';
|
@@ -1,84 +1,37 @@
|
|
1
1
|
import { existsSync, promises } from 'fs';
|
2
|
-
import
|
3
|
-
import { defaultExclude, defaultInclude, configDefaults } from 'vitest/config';
|
2
|
+
import { defaultExclude, defaultInclude, coverageConfigDefaults } from 'vitest/config';
|
4
3
|
import libReport from 'istanbul-lib-report';
|
5
4
|
import reports from 'istanbul-reports';
|
6
5
|
import libCoverage from 'istanbul-lib-coverage';
|
7
6
|
import libSourceMaps from 'istanbul-lib-source-maps';
|
8
7
|
import { createInstrumenter } from 'istanbul-lib-instrument';
|
9
8
|
import _TestExclude from 'test-exclude';
|
10
|
-
import { C as COVERAGE_STORE_KEY } from './index-
|
9
|
+
import { C as COVERAGE_STORE_KEY } from './index-2345780c.js';
|
11
10
|
|
12
11
|
function normalizeWindowsPath(input = "") {
|
13
|
-
if (!input.includes("\\")) {
|
12
|
+
if (!input || !input.includes("\\")) {
|
14
13
|
return input;
|
15
14
|
}
|
16
15
|
return input.replace(/\\/g, "/");
|
17
16
|
}
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
const sep = "/";
|
23
|
-
const delimiter = ":";
|
24
|
-
const normalize = function(path2) {
|
25
|
-
if (path2.length === 0) {
|
26
|
-
return ".";
|
27
|
-
}
|
28
|
-
path2 = normalizeWindowsPath(path2);
|
29
|
-
const isUNCPath = path2.match(_UNC_REGEX);
|
30
|
-
const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX);
|
31
|
-
const isPathAbsolute = isAbsolute(path2);
|
32
|
-
const trailingSeparator = path2[path2.length - 1] === "/";
|
33
|
-
path2 = normalizeString(path2, !isPathAbsolute);
|
34
|
-
if (path2.length === 0) {
|
35
|
-
if (isPathAbsolute) {
|
36
|
-
return "/";
|
37
|
-
}
|
38
|
-
return trailingSeparator ? "./" : ".";
|
39
|
-
}
|
40
|
-
if (trailingSeparator) {
|
41
|
-
path2 += "/";
|
42
|
-
}
|
43
|
-
if (isUNCPath) {
|
44
|
-
if (hasUNCDrive) {
|
45
|
-
return `//./${path2}`;
|
46
|
-
}
|
47
|
-
return `//${path2}`;
|
48
|
-
}
|
49
|
-
return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
|
50
|
-
};
|
51
|
-
const join = function(...args) {
|
52
|
-
if (args.length === 0) {
|
53
|
-
return ".";
|
54
|
-
}
|
55
|
-
let joined;
|
56
|
-
for (let i = 0; i < args.length; ++i) {
|
57
|
-
const arg = args[i];
|
58
|
-
if (arg.length > 0) {
|
59
|
-
if (joined === void 0) {
|
60
|
-
joined = arg;
|
61
|
-
} else {
|
62
|
-
joined += `/${arg}`;
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
if (joined === void 0) {
|
67
|
-
return ".";
|
17
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
18
|
+
function cwd() {
|
19
|
+
if (typeof process !== "undefined") {
|
20
|
+
return process.cwd().replace(/\\/g, "/");
|
68
21
|
}
|
69
|
-
return
|
70
|
-
}
|
71
|
-
const resolve = function(...
|
72
|
-
|
22
|
+
return "/";
|
23
|
+
}
|
24
|
+
const resolve = function(...arguments_) {
|
25
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
73
26
|
let resolvedPath = "";
|
74
27
|
let resolvedAbsolute = false;
|
75
|
-
for (let
|
76
|
-
const
|
77
|
-
if (
|
28
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
29
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
30
|
+
if (!path || path.length === 0) {
|
78
31
|
continue;
|
79
32
|
}
|
80
|
-
resolvedPath = `${
|
81
|
-
resolvedAbsolute = isAbsolute(
|
33
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
34
|
+
resolvedAbsolute = isAbsolute(path);
|
82
35
|
}
|
83
36
|
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
84
37
|
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
@@ -86,22 +39,22 @@ const resolve = function(...args) {
|
|
86
39
|
}
|
87
40
|
return resolvedPath.length > 0 ? resolvedPath : ".";
|
88
41
|
};
|
89
|
-
function normalizeString(
|
42
|
+
function normalizeString(path, allowAboveRoot) {
|
90
43
|
let res = "";
|
91
44
|
let lastSegmentLength = 0;
|
92
45
|
let lastSlash = -1;
|
93
46
|
let dots = 0;
|
94
47
|
let char = null;
|
95
|
-
for (let
|
96
|
-
if (
|
97
|
-
char =
|
48
|
+
for (let index = 0; index <= path.length; ++index) {
|
49
|
+
if (index < path.length) {
|
50
|
+
char = path[index];
|
98
51
|
} else if (char === "/") {
|
99
52
|
break;
|
100
53
|
} else {
|
101
54
|
char = "/";
|
102
55
|
}
|
103
56
|
if (char === "/") {
|
104
|
-
if (lastSlash ===
|
57
|
+
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
105
58
|
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
106
59
|
if (res.length > 2) {
|
107
60
|
const lastSlashIndex = res.lastIndexOf("/");
|
@@ -112,13 +65,13 @@ function normalizeString(path2, allowAboveRoot) {
|
|
112
65
|
res = res.slice(0, lastSlashIndex);
|
113
66
|
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
114
67
|
}
|
115
|
-
lastSlash =
|
68
|
+
lastSlash = index;
|
116
69
|
dots = 0;
|
117
70
|
continue;
|
118
|
-
} else if (res.length
|
71
|
+
} else if (res.length > 0) {
|
119
72
|
res = "";
|
120
73
|
lastSegmentLength = 0;
|
121
|
-
lastSlash =
|
74
|
+
lastSlash = index;
|
122
75
|
dots = 0;
|
123
76
|
continue;
|
124
77
|
}
|
@@ -129,13 +82,13 @@ function normalizeString(path2, allowAboveRoot) {
|
|
129
82
|
}
|
130
83
|
} else {
|
131
84
|
if (res.length > 0) {
|
132
|
-
res += `/${
|
85
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
133
86
|
} else {
|
134
|
-
res =
|
87
|
+
res = path.slice(lastSlash + 1, index);
|
135
88
|
}
|
136
|
-
lastSegmentLength =
|
89
|
+
lastSegmentLength = index - lastSlash - 1;
|
137
90
|
}
|
138
|
-
lastSlash =
|
91
|
+
lastSlash = index;
|
139
92
|
dots = 0;
|
140
93
|
} else if (char === "." && dots !== -1) {
|
141
94
|
++dots;
|
@@ -148,50 +101,20 @@ function normalizeString(path2, allowAboveRoot) {
|
|
148
101
|
const isAbsolute = function(p) {
|
149
102
|
return _IS_ABSOLUTE_RE.test(p);
|
150
103
|
};
|
151
|
-
const toNamespacedPath = function(p) {
|
152
|
-
return normalizeWindowsPath(p);
|
153
|
-
};
|
154
|
-
const extname = function(p) {
|
155
|
-
return path.posix.extname(normalizeWindowsPath(p));
|
156
|
-
};
|
157
104
|
const relative = function(from, to) {
|
158
|
-
|
159
|
-
|
160
|
-
const
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
const parse = function(p) {
|
170
|
-
return path.posix.parse(normalizeWindowsPath(p));
|
105
|
+
const _from = resolve(from).split("/");
|
106
|
+
const _to = resolve(to).split("/");
|
107
|
+
const _fromCopy = [..._from];
|
108
|
+
for (const segment of _fromCopy) {
|
109
|
+
if (_to[0] !== segment) {
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
_from.shift();
|
113
|
+
_to.shift();
|
114
|
+
}
|
115
|
+
return [..._from.map(() => ".."), ..._to].join("/");
|
171
116
|
};
|
172
117
|
|
173
|
-
const _path = /*#__PURE__*/Object.freeze({
|
174
|
-
__proto__: null,
|
175
|
-
sep: sep,
|
176
|
-
delimiter: delimiter,
|
177
|
-
normalize: normalize,
|
178
|
-
join: join,
|
179
|
-
resolve: resolve,
|
180
|
-
normalizeString: normalizeString,
|
181
|
-
isAbsolute: isAbsolute,
|
182
|
-
toNamespacedPath: toNamespacedPath,
|
183
|
-
extname: extname,
|
184
|
-
relative: relative,
|
185
|
-
dirname: dirname,
|
186
|
-
format: format,
|
187
|
-
basename: basename,
|
188
|
-
parse: parse
|
189
|
-
});
|
190
|
-
|
191
|
-
({
|
192
|
-
..._path
|
193
|
-
});
|
194
|
-
|
195
118
|
class IstanbulCoverageProvider {
|
196
119
|
constructor() {
|
197
120
|
this.name = "istanbul";
|
@@ -238,7 +161,7 @@ class IstanbulCoverageProvider {
|
|
238
161
|
await promises.rm(this.options.reportsDirectory, { recursive: true, force: true, maxRetries: 10 });
|
239
162
|
this.coverages = [];
|
240
163
|
}
|
241
|
-
async reportCoverage({ allTestsRun }) {
|
164
|
+
async reportCoverage({ allTestsRun } = {}) {
|
242
165
|
const mergedCoverage = this.coverages.reduce((coverage, previousCoverageMap) => {
|
243
166
|
const map = libCoverage.createCoverageMap(coverage);
|
244
167
|
map.merge(previousCoverageMap);
|
@@ -320,14 +243,14 @@ class IstanbulCoverageProvider {
|
|
320
243
|
}
|
321
244
|
}
|
322
245
|
function resolveIstanbulOptions(options, root) {
|
323
|
-
const reportsDirectory = resolve(root, options.reportsDirectory ||
|
246
|
+
const reportsDirectory = resolve(root, options.reportsDirectory || coverageConfigDefaults.reportsDirectory);
|
247
|
+
const reporter = options.reporter || coverageConfigDefaults.reporter;
|
324
248
|
const resolved = {
|
325
|
-
...
|
249
|
+
...coverageConfigDefaults,
|
326
250
|
...options,
|
327
251
|
provider: "istanbul",
|
328
252
|
reportsDirectory,
|
329
|
-
|
330
|
-
reporter: Array.isArray(options.reporter) ? options.reporter : [options.reporter]
|
253
|
+
reporter: Array.isArray(reporter) ? reporter : [reporter]
|
331
254
|
};
|
332
255
|
return resolved;
|
333
256
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/coverage-istanbul",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.28.0",
|
5
5
|
"description": "Istanbul coverage provider for Vitest",
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
7
7
|
"license": "MIT",
|
@@ -43,7 +43,7 @@
|
|
43
43
|
"istanbul-lib-source-maps": "^4.0.1",
|
44
44
|
"istanbul-reports": "^3.1.5",
|
45
45
|
"test-exclude": "^6.0.0",
|
46
|
-
"vitest": "0.
|
46
|
+
"vitest": "0.28.0"
|
47
47
|
},
|
48
48
|
"devDependencies": {
|
49
49
|
"@types/istanbul-lib-coverage": "^2.0.4",
|
@@ -51,7 +51,7 @@
|
|
51
51
|
"@types/istanbul-lib-report": "^3.0.0",
|
52
52
|
"@types/istanbul-lib-source-maps": "^4.0.1",
|
53
53
|
"@types/istanbul-reports": "^3.0.1",
|
54
|
-
"pathe": "^
|
54
|
+
"pathe": "^1.1.0"
|
55
55
|
},
|
56
56
|
"scripts": {
|
57
57
|
"build": "rimraf dist && rollup -c",
|