@vitest/coverage-v8 1.3.0 → 1.3.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/LICENSE +1 -2
- package/dist/provider.js +17 -48
- 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
@@ -170,6 +170,7 @@ function cleanUrl(url) {
|
|
170
170
|
|
171
171
|
const WRAPPER_LENGTH = 185;
|
172
172
|
const VITE_EXPORTS_LINE_PATTERN = /Object\.defineProperty\(__vite_ssr_exports__.*\n/g;
|
173
|
+
const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes"(\s|.)+?]\),/g;
|
173
174
|
const DEFAULT_PROJECT = Symbol.for("default-project");
|
174
175
|
const debug = createDebug("vitest:coverage");
|
175
176
|
let uniqueId = 0;
|
@@ -253,7 +254,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
253
254
|
for (const [projectName, coveragePerProject] of this.coverageFiles.entries()) {
|
254
255
|
for (const [transformMode, filenames] of Object.entries(coveragePerProject)) {
|
255
256
|
let merged = { result: [] };
|
256
|
-
for (const chunk of toSlices(filenames, this.options.processingConcurrency)) {
|
257
|
+
for (const chunk of this.toSlices(filenames, this.options.processingConcurrency)) {
|
257
258
|
if (debug.enabled) {
|
258
259
|
index += chunk.length;
|
259
260
|
debug("Covered files %d/%d", index, total);
|
@@ -280,7 +281,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
280
281
|
coverageMap,
|
281
282
|
watermarks: this.options.watermarks
|
282
283
|
});
|
283
|
-
if (hasTerminalReporter(this.options.reporter))
|
284
|
+
if (this.hasTerminalReporter(this.options.reporter))
|
284
285
|
this.ctx.logger.log(c.blue(" % ") + c.dim("Coverage report from ") + c.yellow(this.name));
|
285
286
|
for (const reporter of this.options.reporter) {
|
286
287
|
reports.create(reporter[0], {
|
@@ -307,10 +308,8 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
307
308
|
this.updateThresholds({
|
308
309
|
thresholds: resolvedThresholds,
|
309
310
|
perFile: this.options.thresholds.perFile,
|
310
|
-
configurationFile:
|
311
|
-
|
312
|
-
read: () => resolveConfig(configModule)
|
313
|
-
}
|
311
|
+
configurationFile: configModule,
|
312
|
+
onUpdate: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8")
|
314
313
|
});
|
315
314
|
}
|
316
315
|
}
|
@@ -323,7 +322,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
323
322
|
const uncoveredFiles = includedFiles.map((file) => pathToFileURL(resolve(this.ctx.config.root, file))).filter((file) => !testedFiles.includes(file.pathname));
|
324
323
|
let merged = { result: [] };
|
325
324
|
let index = 0;
|
326
|
-
for (const chunk of toSlices(uncoveredFiles, this.options.processingConcurrency)) {
|
325
|
+
for (const chunk of this.toSlices(uncoveredFiles, this.options.processingConcurrency)) {
|
327
326
|
if (debug.enabled) {
|
328
327
|
index += chunk.length;
|
329
328
|
debug("Uncovered files %d/%d", index, uncoveredFiles.length);
|
@@ -366,7 +365,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
366
365
|
originalSource: sourcesContent,
|
367
366
|
source: code || sourcesContent,
|
368
367
|
sourceMap: {
|
369
|
-
sourcemap:
|
368
|
+
sourcemap: excludeGeneratedCode(code, {
|
370
369
|
...map,
|
371
370
|
version: 3,
|
372
371
|
sources: [url],
|
@@ -382,7 +381,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
382
381
|
const scriptCoverages = coverage.result.filter((result) => this.testExclude.shouldInstrument(fileURLToPath(result.url)));
|
383
382
|
const coverageMap = libCoverage.createCoverageMap({});
|
384
383
|
let index = 0;
|
385
|
-
for (const chunk of toSlices(scriptCoverages, this.options.processingConcurrency)) {
|
384
|
+
for (const chunk of this.toSlices(scriptCoverages, this.options.processingConcurrency)) {
|
386
385
|
if (debug.enabled) {
|
387
386
|
index += chunk.length;
|
388
387
|
debug("Converting %d/%d", index, scriptCoverages.length);
|
@@ -403,16 +402,17 @@ async function transformCoverage(coverageMap) {
|
|
403
402
|
const sourceMapStore = libSourceMaps.createSourceMapStore();
|
404
403
|
return await sourceMapStore.transformCoverage(coverageMap);
|
405
404
|
}
|
406
|
-
function
|
407
|
-
if (!source
|
405
|
+
function excludeGeneratedCode(source, map) {
|
406
|
+
if (!source)
|
407
|
+
return map;
|
408
|
+
if (!source.match(VITE_EXPORTS_LINE_PATTERN) && !source.match(DECORATOR_METADATA_PATTERN))
|
408
409
|
return map;
|
409
|
-
const
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
});
|
410
|
+
const trimmed = new MagicString(source);
|
411
|
+
trimmed.replaceAll(VITE_EXPORTS_LINE_PATTERN, "\n");
|
412
|
+
trimmed.replaceAll(DECORATOR_METADATA_PATTERN, (match) => "\n".repeat(match.split("\n").length - 1));
|
413
|
+
const trimmedMap = trimmed.generateMap({ hires: "boundary" });
|
414
414
|
const combinedMap = remapping(
|
415
|
-
[{ ...
|
415
|
+
[{ ...trimmedMap, version: 3 }, map],
|
416
416
|
() => null
|
417
417
|
);
|
418
418
|
return combinedMap;
|
@@ -432,36 +432,5 @@ function normalizeTransformResults(fetchCache) {
|
|
432
432
|
}
|
433
433
|
return normalized;
|
434
434
|
}
|
435
|
-
function hasTerminalReporter(reporters) {
|
436
|
-
return reporters.some(([reporter]) => reporter === "text" || reporter === "text-summary" || reporter === "text-lcov" || reporter === "teamcity");
|
437
|
-
}
|
438
|
-
function toSlices(array, size) {
|
439
|
-
return array.reduce((chunks, item) => {
|
440
|
-
const index = Math.max(0, chunks.length - 1);
|
441
|
-
const lastChunk = chunks[index] || [];
|
442
|
-
chunks[index] = lastChunk;
|
443
|
-
if (lastChunk.length >= size)
|
444
|
-
chunks.push([item]);
|
445
|
-
else
|
446
|
-
lastChunk.push(item);
|
447
|
-
return chunks;
|
448
|
-
}, []);
|
449
|
-
}
|
450
|
-
function resolveConfig(configModule) {
|
451
|
-
const mod = configModule.exports.default;
|
452
|
-
try {
|
453
|
-
if (mod.$type === "object")
|
454
|
-
return mod;
|
455
|
-
if (mod.$type === "function-call") {
|
456
|
-
if (mod.$args[0].$type === "object")
|
457
|
-
return mod.$args[0];
|
458
|
-
if (mod.$args[0].$type === "arrow-function-expression" && mod.$args[0].$body.$type === "object")
|
459
|
-
return mod.$args[0].$body;
|
460
|
-
}
|
461
|
-
} catch (error) {
|
462
|
-
throw new Error(error instanceof Error ? error.message : String(error));
|
463
|
-
}
|
464
|
-
throw new Error("Failed to update coverage thresholds. Configuration file is too complex.");
|
465
|
-
}
|
466
435
|
|
467
436
|
export { V8CoverageProvider };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/coverage-v8",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.3.
|
4
|
+
"version": "1.3.1",
|
5
5
|
"description": "V8 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": "1.3.
|
40
|
+
"vitest": "1.3.1"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
43
|
"@ampproject/remapping": "^2.2.1",
|
@@ -61,8 +61,8 @@
|
|
61
61
|
"@types/istanbul-lib-source-maps": "^4.0.4",
|
62
62
|
"@types/istanbul-reports": "^3.0.4",
|
63
63
|
"pathe": "^1.1.1",
|
64
|
-
"vite-node": "1.3.
|
65
|
-
"vitest": "1.3.
|
64
|
+
"vite-node": "1.3.1",
|
65
|
+
"vitest": "1.3.1"
|
66
66
|
},
|
67
67
|
"scripts": {
|
68
68
|
"build": "rimraf dist && rollup -c",
|