@vitest/coverage-istanbul 3.2.3 → 4.0.0-beta.1
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.
- package/dist/provider.d.ts +0 -2
- package/dist/provider.js +7 -116
- package/package.json +3 -5
package/dist/provider.d.ts
CHANGED
@@ -2,14 +2,12 @@ import libCoverage, { CoverageMap } from 'istanbul-lib-coverage';
|
|
2
2
|
import { Instrumenter } from 'istanbul-lib-instrument';
|
3
3
|
import { ProxifiedModule } from 'magicast';
|
4
4
|
import { ResolvedCoverageOptions, CoverageProvider, Vitest, ReportContext } from 'vitest/node';
|
5
|
-
import TestExclude from 'test-exclude';
|
6
5
|
import { BaseCoverageProvider } from 'vitest/coverage';
|
7
6
|
|
8
7
|
declare class IstanbulCoverageProvider extends BaseCoverageProvider<ResolvedCoverageOptions<"istanbul">> implements CoverageProvider {
|
9
8
|
name: "istanbul";
|
10
9
|
version: string;
|
11
10
|
instrumenter: Instrumenter;
|
12
|
-
testExclude: InstanceType<typeof TestExclude>;
|
13
11
|
initialize(ctx: Vitest): void;
|
14
12
|
onFileTransform(sourceCode: string, id: string, pluginCtx: any): {
|
15
13
|
code: string
|
package/dist/provider.js
CHANGED
@@ -7,124 +7,20 @@ import libReport from 'istanbul-lib-report';
|
|
7
7
|
import libSourceMaps from 'istanbul-lib-source-maps';
|
8
8
|
import reports from 'istanbul-reports';
|
9
9
|
import { parseModule } from 'magicast';
|
10
|
-
import TestExclude from 'test-exclude';
|
11
10
|
import c from 'tinyrainbow';
|
12
11
|
import { BaseCoverageProvider } from 'vitest/coverage';
|
12
|
+
import { isCSSRequest } from 'vitest/node';
|
13
13
|
import { C as COVERAGE_STORE_KEY } from './constants-BCJfMgEg.js';
|
14
14
|
|
15
|
-
|
16
|
-
function normalizeWindowsPath(input = "") {
|
17
|
-
if (!input) {
|
18
|
-
return input;
|
19
|
-
}
|
20
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
21
|
-
}
|
22
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
23
|
-
function cwd() {
|
24
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
25
|
-
return process.cwd().replace(/\\/g, "/");
|
26
|
-
}
|
27
|
-
return "/";
|
28
|
-
}
|
29
|
-
const resolve = function(...arguments_) {
|
30
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
31
|
-
let resolvedPath = "";
|
32
|
-
let resolvedAbsolute = false;
|
33
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
34
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
35
|
-
if (!path || path.length === 0) {
|
36
|
-
continue;
|
37
|
-
}
|
38
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
39
|
-
resolvedAbsolute = isAbsolute(path);
|
40
|
-
}
|
41
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
42
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
43
|
-
return `/${resolvedPath}`;
|
44
|
-
}
|
45
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
46
|
-
};
|
47
|
-
function normalizeString(path, allowAboveRoot) {
|
48
|
-
let res = "";
|
49
|
-
let lastSegmentLength = 0;
|
50
|
-
let lastSlash = -1;
|
51
|
-
let dots = 0;
|
52
|
-
let char = null;
|
53
|
-
for (let index = 0; index <= path.length; ++index) {
|
54
|
-
if (index < path.length) {
|
55
|
-
char = path[index];
|
56
|
-
} else if (char === "/") {
|
57
|
-
break;
|
58
|
-
} else {
|
59
|
-
char = "/";
|
60
|
-
}
|
61
|
-
if (char === "/") {
|
62
|
-
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
63
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
64
|
-
if (res.length > 2) {
|
65
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
66
|
-
if (lastSlashIndex === -1) {
|
67
|
-
res = "";
|
68
|
-
lastSegmentLength = 0;
|
69
|
-
} else {
|
70
|
-
res = res.slice(0, lastSlashIndex);
|
71
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
72
|
-
}
|
73
|
-
lastSlash = index;
|
74
|
-
dots = 0;
|
75
|
-
continue;
|
76
|
-
} else if (res.length > 0) {
|
77
|
-
res = "";
|
78
|
-
lastSegmentLength = 0;
|
79
|
-
lastSlash = index;
|
80
|
-
dots = 0;
|
81
|
-
continue;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
if (allowAboveRoot) {
|
85
|
-
res += res.length > 0 ? "/.." : "..";
|
86
|
-
lastSegmentLength = 2;
|
87
|
-
}
|
88
|
-
} else {
|
89
|
-
if (res.length > 0) {
|
90
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
91
|
-
} else {
|
92
|
-
res = path.slice(lastSlash + 1, index);
|
93
|
-
}
|
94
|
-
lastSegmentLength = index - lastSlash - 1;
|
95
|
-
}
|
96
|
-
lastSlash = index;
|
97
|
-
dots = 0;
|
98
|
-
} else if (char === "." && dots !== -1) {
|
99
|
-
++dots;
|
100
|
-
} else {
|
101
|
-
dots = -1;
|
102
|
-
}
|
103
|
-
}
|
104
|
-
return res;
|
105
|
-
}
|
106
|
-
const isAbsolute = function(p) {
|
107
|
-
return _IS_ABSOLUTE_RE.test(p);
|
108
|
-
};
|
109
|
-
|
110
|
-
var version = "3.2.3";
|
15
|
+
var version = "4.0.0-beta.1";
|
111
16
|
|
112
17
|
const debug = createDebug("vitest:coverage");
|
113
18
|
class IstanbulCoverageProvider extends BaseCoverageProvider {
|
114
19
|
name = "istanbul";
|
115
20
|
version = version;
|
116
21
|
instrumenter;
|
117
|
-
testExclude;
|
118
22
|
initialize(ctx) {
|
119
23
|
this._initialize(ctx);
|
120
|
-
this.testExclude = new TestExclude({
|
121
|
-
cwd: ctx.config.root,
|
122
|
-
include: this.options.include,
|
123
|
-
exclude: this.options.exclude,
|
124
|
-
excludeNodeModules: true,
|
125
|
-
extension: this.options.extension,
|
126
|
-
relativePath: !this.options.allowExternal
|
127
|
-
});
|
128
24
|
this.instrumenter = createInstrumenter({
|
129
25
|
produceSourceMap: true,
|
130
26
|
autoWrap: false,
|
@@ -142,10 +38,10 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
142
38
|
// Istanbul/babel cannot instrument CSS - e.g. Vue imports end up here.
|
143
39
|
// File extension itself is .vue, but it contains CSS.
|
144
40
|
// e.g. "Example.vue?vue&type=style&index=0&scoped=f7f04e08&lang.css"
|
145
|
-
if (id
|
41
|
+
if (isCSSRequest(id)) {
|
146
42
|
return;
|
147
43
|
}
|
148
|
-
if (!this.
|
44
|
+
if (!this.isIncluded(removeQueryParameters(id))) {
|
149
45
|
return;
|
150
46
|
}
|
151
47
|
const sourceMap = pluginCtx.getCombinedSourcemap();
|
@@ -180,13 +76,13 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
180
76
|
});
|
181
77
|
// Include untested files when all tests were run (not a single file re-run)
|
182
78
|
// or if previous results are preserved by "cleanOnRerun: false"
|
183
|
-
if (this.options.
|
79
|
+
if (this.options.include != null && (allTestsRun || !this.options.cleanOnRerun)) {
|
184
80
|
const coveredFiles = coverageMap.files();
|
185
81
|
const uncoveredCoverage = await this.getCoverageMapForUncoveredFiles(coveredFiles);
|
186
82
|
coverageMap.merge(await transformCoverage(uncoveredCoverage));
|
187
83
|
}
|
188
84
|
if (this.options.excludeAfterRemap) {
|
189
|
-
coverageMap.filter((filename) => this.
|
85
|
+
coverageMap.filter((filename) => this.isIncluded(filename));
|
190
86
|
}
|
191
87
|
if (debug.enabled) {
|
192
88
|
debug("Generate coverage total time %d ms", (performance.now() - start).toFixed());
|
@@ -218,12 +114,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
218
114
|
return parseModule(await promises.readFile(configFilePath, "utf8"));
|
219
115
|
}
|
220
116
|
async getCoverageMapForUncoveredFiles(coveredFiles) {
|
221
|
-
const
|
222
|
-
let includedFiles = allFiles.map((file) => resolve(this.ctx.config.root, file));
|
223
|
-
if (this.ctx.config.changed) {
|
224
|
-
includedFiles = (this.ctx.config.related || []).filter((file) => includedFiles.includes(file));
|
225
|
-
}
|
226
|
-
const uncoveredFiles = includedFiles.filter((file) => !coveredFiles.includes(file)).sort();
|
117
|
+
const uncoveredFiles = await this.getUntestedFiles(coveredFiles);
|
227
118
|
const cacheKey = new Date().getTime();
|
228
119
|
const coverageMap = this.createCoverageMap();
|
229
120
|
const transform = this.createUncoveredFileTransformer(this.ctx);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/coverage-istanbul",
|
3
3
|
"type": "module",
|
4
|
-
"version": "
|
4
|
+
"version": "4.0.0-beta.1",
|
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": "
|
40
|
+
"vitest": "4.0.0-beta.1"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
43
|
"@istanbuljs/schema": "^0.1.3",
|
@@ -48,7 +48,6 @@
|
|
48
48
|
"istanbul-lib-source-maps": "^5.0.6",
|
49
49
|
"istanbul-reports": "^3.1.7",
|
50
50
|
"magicast": "^0.3.5",
|
51
|
-
"test-exclude": "^7.0.1",
|
52
51
|
"tinyrainbow": "^2.0.0"
|
53
52
|
},
|
54
53
|
"devDependencies": {
|
@@ -58,9 +57,8 @@
|
|
58
57
|
"@types/istanbul-lib-report": "^3.0.3",
|
59
58
|
"@types/istanbul-lib-source-maps": "^4.0.4",
|
60
59
|
"@types/istanbul-reports": "^3.0.4",
|
61
|
-
"@types/test-exclude": "^6.0.2",
|
62
60
|
"pathe": "^2.0.3",
|
63
|
-
"vitest": "
|
61
|
+
"vitest": "4.0.0-beta.1"
|
64
62
|
},
|
65
63
|
"scripts": {
|
66
64
|
"build": "rimraf dist && rollup -c",
|