@vitest/coverage-istanbul 1.3.0 → 1.4.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.
- package/LICENSE +1 -2
- package/dist/provider.js +12 -42
- package/package.json +4 -4
package/LICENSE
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2021-Present
|
4
|
-
Copyright (c) 2021-Present Matias Capeletto <https://github.com/patak-dev>
|
3
|
+
Copyright (c) 2021-Present Vitest Team
|
5
4
|
|
6
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/provider.js
CHANGED
@@ -168,6 +168,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
168
168
|
return;
|
169
169
|
const sourceMap = pluginCtx.getCombinedSourcemap();
|
170
170
|
sourceMap.sources = sourceMap.sources.map(removeQueryParameters);
|
171
|
+
sourceCode = sourceCode.replaceAll("_ts_decorate", "/* istanbul ignore next */_ts_decorate");
|
171
172
|
const code = this.instrumenter.instrumentSync(sourceCode, id, sourceMap);
|
172
173
|
const map = this.instrumenter.lastSourceMap();
|
173
174
|
return { code, map };
|
@@ -210,7 +211,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
210
211
|
for (const coveragePerProject of this.coverageFiles.values()) {
|
211
212
|
for (const filenames of [coveragePerProject.ssr, coveragePerProject.web]) {
|
212
213
|
const coverageMapByTransformMode = libCoverage.createCoverageMap({});
|
213
|
-
for (const chunk of toSlices(filenames, this.options.processingConcurrency)) {
|
214
|
+
for (const chunk of this.toSlices(filenames, this.options.processingConcurrency)) {
|
214
215
|
if (debug.enabled) {
|
215
216
|
index += chunk.length;
|
216
217
|
debug("Covered files %d/%d", index, total);
|
@@ -235,7 +236,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
235
236
|
coverageMap,
|
236
237
|
watermarks: this.options.watermarks
|
237
238
|
});
|
238
|
-
if (hasTerminalReporter(this.options.reporter))
|
239
|
+
if (this.hasTerminalReporter(this.options.reporter))
|
239
240
|
this.ctx.logger.log(c.blue(" % ") + c.dim("Coverage report from ") + c.yellow(this.name));
|
240
241
|
for (const reporter of this.options.reporter) {
|
241
242
|
reports.create(reporter[0], {
|
@@ -262,10 +263,8 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
262
263
|
this.updateThresholds({
|
263
264
|
thresholds: resolvedThresholds,
|
264
265
|
perFile: this.options.thresholds.perFile,
|
265
|
-
configurationFile:
|
266
|
-
|
267
|
-
read: () => resolveConfig(configModule)
|
268
|
-
}
|
266
|
+
configurationFile: configModule,
|
267
|
+
onUpdate: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8")
|
269
268
|
});
|
270
269
|
}
|
271
270
|
}
|
@@ -273,14 +272,16 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
273
272
|
this.coverageFiles = /* @__PURE__ */ new Map();
|
274
273
|
}
|
275
274
|
async getCoverageMapForUncoveredFiles(coveredFiles) {
|
276
|
-
const
|
277
|
-
|
275
|
+
const allFiles = await this.testExclude.glob(this.ctx.config.root);
|
276
|
+
let includedFiles = allFiles.map((file) => resolve(this.ctx.config.root, file));
|
277
|
+
if (this.ctx.config.changed)
|
278
|
+
includedFiles = (this.ctx.config.related || []).filter((file) => includedFiles.includes(file));
|
279
|
+
const uncoveredFiles = includedFiles.filter((file) => !coveredFiles.includes(file));
|
280
|
+
const cacheKey = (/* @__PURE__ */ new Date()).getTime();
|
278
281
|
const coverageMap = libCoverage.createCoverageMap({});
|
279
282
|
for (const [index, filename] of uncoveredFiles.entries()) {
|
280
283
|
debug("Uncovered file %s %d/%d", filename, index, uncoveredFiles.length);
|
281
|
-
|
282
|
-
this.ctx.vitenode.fetchCache.delete(filename);
|
283
|
-
await this.ctx.vitenode.transformRequest(filename);
|
284
|
+
await this.ctx.vitenode.transformRequest(`${filename}?v=${cacheKey}`);
|
284
285
|
const lastCoverage = this.instrumenter.lastFileCoverage();
|
285
286
|
coverageMap.addFileCoverage(lastCoverage);
|
286
287
|
}
|
@@ -316,36 +317,5 @@ function includeImplicitElseBranches(coverageMap) {
|
|
316
317
|
function isEmptyCoverageRange(range) {
|
317
318
|
return range.start === void 0 || range.start.line === void 0 || range.start.column === void 0 || range.end === void 0 || range.end.line === void 0 || range.end.column === void 0;
|
318
319
|
}
|
319
|
-
function hasTerminalReporter(reporters) {
|
320
|
-
return reporters.some(([reporter]) => reporter === "text" || reporter === "text-summary" || reporter === "text-lcov" || reporter === "teamcity");
|
321
|
-
}
|
322
|
-
function toSlices(array, size) {
|
323
|
-
return array.reduce((chunks, item) => {
|
324
|
-
const index = Math.max(0, chunks.length - 1);
|
325
|
-
const lastChunk = chunks[index] || [];
|
326
|
-
chunks[index] = lastChunk;
|
327
|
-
if (lastChunk.length >= size)
|
328
|
-
chunks.push([item]);
|
329
|
-
else
|
330
|
-
lastChunk.push(item);
|
331
|
-
return chunks;
|
332
|
-
}, []);
|
333
|
-
}
|
334
|
-
function resolveConfig(configModule) {
|
335
|
-
const mod = configModule.exports.default;
|
336
|
-
try {
|
337
|
-
if (mod.$type === "object")
|
338
|
-
return mod;
|
339
|
-
if (mod.$type === "function-call") {
|
340
|
-
if (mod.$args[0].$type === "object")
|
341
|
-
return mod.$args[0];
|
342
|
-
if (mod.$args[0].$type === "arrow-function-expression" && mod.$args[0].$body.$type === "object")
|
343
|
-
return mod.$args[0].$body;
|
344
|
-
}
|
345
|
-
} catch (error) {
|
346
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
347
|
-
}
|
348
|
-
throw new Error("Failed to update coverage thresholds. Configuration file is too complex.");
|
349
|
-
}
|
350
320
|
|
351
321
|
export { IstanbulCoverageProvider };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/coverage-istanbul",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.4.0",
|
5
5
|
"description": "Istanbul coverage provider for Vitest",
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
7
7
|
"license": "MIT",
|
@@ -37,14 +37,14 @@
|
|
37
37
|
"dist"
|
38
38
|
],
|
39
39
|
"peerDependencies": {
|
40
|
-
"vitest": "1.
|
40
|
+
"vitest": "1.4.0"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
43
|
"debug": "^4.3.4",
|
44
44
|
"istanbul-lib-coverage": "^3.2.2",
|
45
45
|
"istanbul-lib-instrument": "^6.0.1",
|
46
46
|
"istanbul-lib-report": "^3.0.1",
|
47
|
-
"istanbul-lib-source-maps": "^
|
47
|
+
"istanbul-lib-source-maps": "^5.0.4",
|
48
48
|
"istanbul-reports": "^3.1.6",
|
49
49
|
"magicast": "^0.3.3",
|
50
50
|
"picocolors": "^1.0.0",
|
@@ -58,7 +58,7 @@
|
|
58
58
|
"@types/istanbul-lib-source-maps": "^4.0.4",
|
59
59
|
"@types/istanbul-reports": "^3.0.4",
|
60
60
|
"pathe": "^1.1.1",
|
61
|
-
"vitest": "1.
|
61
|
+
"vitest": "1.4.0"
|
62
62
|
},
|
63
63
|
"scripts": {
|
64
64
|
"build": "rimraf dist && rollup -c",
|