@vitest/coverage-v8 1.3.1 → 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/dist/provider.js +27 -9
- package/package.json +6 -5
package/dist/provider.js
CHANGED
@@ -11,6 +11,7 @@ import { parseModule } from 'magicast';
|
|
11
11
|
import remapping from '@ampproject/remapping';
|
12
12
|
import c from 'picocolors';
|
13
13
|
import { provider } from 'std-env';
|
14
|
+
import { stripLiteral } from 'strip-literal';
|
14
15
|
import createDebug from 'debug';
|
15
16
|
import { builtinModules } from 'node:module';
|
16
17
|
import { coverageConfigDefaults, defaultExclude, defaultInclude } from 'vitest/config';
|
@@ -170,7 +171,7 @@ function cleanUrl(url) {
|
|
170
171
|
|
171
172
|
const WRAPPER_LENGTH = 185;
|
172
173
|
const VITE_EXPORTS_LINE_PATTERN = /Object\.defineProperty\(__vite_ssr_exports__.*\n/g;
|
173
|
-
const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes"
|
174
|
+
const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes", \[[^\]]*?\]\),*/g;
|
174
175
|
const DEFAULT_PROJECT = Symbol.for("default-project");
|
175
176
|
const debug = createDebug("vitest:coverage");
|
176
177
|
let uniqueId = 0;
|
@@ -318,8 +319,11 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
318
319
|
}
|
319
320
|
async getUntestedFiles(testedFiles) {
|
320
321
|
const transformResults = normalizeTransformResults(this.ctx.vitenode.fetchCache);
|
321
|
-
const
|
322
|
-
|
322
|
+
const allFiles = await this.testExclude.glob(this.ctx.config.root);
|
323
|
+
let includedFiles = allFiles.map((file) => resolve(this.ctx.config.root, file));
|
324
|
+
if (this.ctx.config.changed)
|
325
|
+
includedFiles = (this.ctx.config.related || []).filter((file) => includedFiles.includes(file));
|
326
|
+
const uncoveredFiles = includedFiles.map((file) => pathToFileURL(file)).filter((file) => !testedFiles.includes(file.pathname));
|
323
327
|
let merged = { result: [] };
|
324
328
|
let index = 0;
|
325
329
|
for (const chunk of this.toSlices(uncoveredFiles, this.options.processingConcurrency)) {
|
@@ -328,7 +332,11 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
328
332
|
debug("Uncovered files %d/%d", index, uncoveredFiles.length);
|
329
333
|
}
|
330
334
|
const coverages = await Promise.all(chunk.map(async (filename) => {
|
331
|
-
const
|
335
|
+
const transformResult = await this.ctx.vitenode.transformRequest(filename.pathname).catch(() => {
|
336
|
+
});
|
337
|
+
if (transformResult && stripLiteral(transformResult.code).trim() === "")
|
338
|
+
return null;
|
339
|
+
const { originalSource } = await this.getSources(filename.href, transformResults);
|
332
340
|
const coverage = {
|
333
341
|
url: filename.href,
|
334
342
|
scriptId: "0",
|
@@ -336,7 +344,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
336
344
|
functions: [{
|
337
345
|
ranges: [{
|
338
346
|
startOffset: 0,
|
339
|
-
endOffset:
|
347
|
+
endOffset: originalSource.length,
|
340
348
|
count: 0
|
341
349
|
}],
|
342
350
|
isBlockCoverage: true,
|
@@ -346,7 +354,10 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
346
354
|
};
|
347
355
|
return { result: [coverage] };
|
348
356
|
}));
|
349
|
-
merged = mergeProcessCovs([
|
357
|
+
merged = mergeProcessCovs([
|
358
|
+
merged,
|
359
|
+
...coverages.filter((cov) => cov != null)
|
360
|
+
]);
|
350
361
|
}
|
351
362
|
return merged;
|
352
363
|
}
|
@@ -359,8 +370,15 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
359
370
|
const length = findLongestFunctionLength(functions);
|
360
371
|
return ".".repeat(length);
|
361
372
|
});
|
362
|
-
if (!map)
|
363
|
-
return {
|
373
|
+
if (!map) {
|
374
|
+
return {
|
375
|
+
source: code || sourcesContent,
|
376
|
+
originalSource: sourcesContent
|
377
|
+
};
|
378
|
+
}
|
379
|
+
const sources = [url];
|
380
|
+
if (map.sources && map.sources[0] && !url.endsWith(map.sources[0]))
|
381
|
+
sources[0] = new URL(map.sources[0], url).href;
|
364
382
|
return {
|
365
383
|
originalSource: sourcesContent,
|
366
384
|
source: code || sourcesContent,
|
@@ -368,7 +386,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
368
386
|
sourcemap: excludeGeneratedCode(code, {
|
369
387
|
...map,
|
370
388
|
version: 3,
|
371
|
-
sources
|
389
|
+
sources,
|
372
390
|
sourcesContent: [sourcesContent]
|
373
391
|
})
|
374
392
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/coverage-v8",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.4.0",
|
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.
|
40
|
+
"vitest": "1.4.0"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
43
|
"@ampproject/remapping": "^2.2.1",
|
@@ -45,12 +45,13 @@
|
|
45
45
|
"debug": "^4.3.4",
|
46
46
|
"istanbul-lib-coverage": "^3.2.2",
|
47
47
|
"istanbul-lib-report": "^3.0.1",
|
48
|
-
"istanbul-lib-source-maps": "^
|
48
|
+
"istanbul-lib-source-maps": "^5.0.4",
|
49
49
|
"istanbul-reports": "^3.1.6",
|
50
50
|
"magic-string": "^0.30.5",
|
51
51
|
"magicast": "^0.3.3",
|
52
52
|
"picocolors": "^1.0.0",
|
53
53
|
"std-env": "^3.5.0",
|
54
|
+
"strip-literal": "^2.0.0",
|
54
55
|
"test-exclude": "^6.0.0",
|
55
56
|
"v8-to-istanbul": "^9.2.0"
|
56
57
|
},
|
@@ -61,8 +62,8 @@
|
|
61
62
|
"@types/istanbul-lib-source-maps": "^4.0.4",
|
62
63
|
"@types/istanbul-reports": "^3.0.4",
|
63
64
|
"pathe": "^1.1.1",
|
64
|
-
"vite-node": "1.
|
65
|
-
"vitest": "1.
|
65
|
+
"vite-node": "1.4.0",
|
66
|
+
"vitest": "1.4.0"
|
66
67
|
},
|
67
68
|
"scripts": {
|
68
69
|
"build": "rimraf dist && rollup -c",
|