@depup/vitest__coverage-v8 4.1.0-depup.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 +21 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/dist/browser.d.ts +5 -0
- package/dist/browser.js +64 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +67 -0
- package/dist/load-provider-CdgAx3rL.js +11 -0
- package/dist/pathe.M-eThtNZ-BTaAGrLg.js +104 -0
- package/dist/provider.d.ts +24 -0
- package/dist/provider.js +297 -0
- package/package.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @depup/vitest__coverage-v8
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [@vitest/coverage-v8](https://www.npmjs.com/package/@vitest/coverage-v8)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/vitest__coverage-v8
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [@vitest/coverage-v8](https://www.npmjs.com/package/@vitest/coverage-v8) @ 4.1.0 |
|
|
17
|
+
| Processed | 2026-03-17 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 1 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| tinyrainbow | ^3.0.3 | ^3.1.0 |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@vitest/coverage-v8
|
|
30
|
+
|
|
31
|
+
License inherited from the original package.
|
package/changes.json
ADDED
package/dist/browser.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { cdp } from 'vitest/browser';
|
|
2
|
+
import { l as loadProvider } from './load-provider-CdgAx3rL.js';
|
|
3
|
+
|
|
4
|
+
const session = cdp();
|
|
5
|
+
let enabled = false;
|
|
6
|
+
const mod = {
|
|
7
|
+
async startCoverage() {
|
|
8
|
+
if (enabled) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
enabled = true;
|
|
12
|
+
await session.send("Profiler.enable");
|
|
13
|
+
await session.send("Profiler.startPreciseCoverage", {
|
|
14
|
+
callCount: true,
|
|
15
|
+
detailed: true
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
async takeCoverage() {
|
|
19
|
+
const coverage = await session.send("Profiler.takePreciseCoverage");
|
|
20
|
+
const result = [];
|
|
21
|
+
// Reduce amount of data sent over rpc by doing some early result filtering
|
|
22
|
+
for (const entry of coverage.result) {
|
|
23
|
+
if (filterResult(entry)) {
|
|
24
|
+
result.push({
|
|
25
|
+
...entry,
|
|
26
|
+
url: decodeURIComponent(entry.url.replace(window.location.origin, ""))
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { result };
|
|
31
|
+
},
|
|
32
|
+
stopCoverage() {
|
|
33
|
+
// Browser mode should not stop coverage as same V8 instance is shared between tests
|
|
34
|
+
},
|
|
35
|
+
async getProvider() {
|
|
36
|
+
return loadProvider();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function filterResult(coverage) {
|
|
40
|
+
if (!coverage.url.startsWith(window.location.origin)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (coverage.url.includes("/node_modules/")) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (coverage.url.includes("__vitest_browser__")) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (coverage.url.includes("__vitest__/assets")) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (coverage.url === window.location.href) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (coverage.url.includes("/@id/@vitest/")) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (coverage.url.includes("/@vite/client")) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { mod as default };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import inspector from 'node:inspector/promises';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { provider } from 'std-env';
|
|
4
|
+
import { l as loadProvider } from './load-provider-CdgAx3rL.js';
|
|
5
|
+
import { n as normalize } from './pathe.M-eThtNZ-BTaAGrLg.js';
|
|
6
|
+
|
|
7
|
+
const session = new inspector.Session();
|
|
8
|
+
let enabled = false;
|
|
9
|
+
const mod = {
|
|
10
|
+
async startCoverage({ isolate }) {
|
|
11
|
+
if (isolate === false && enabled) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
enabled = true;
|
|
15
|
+
session.connect();
|
|
16
|
+
await session.post("Profiler.enable");
|
|
17
|
+
await session.post("Profiler.startPreciseCoverage", {
|
|
18
|
+
callCount: true,
|
|
19
|
+
detailed: true
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
async takeCoverage(options) {
|
|
23
|
+
if (provider === "stackblitz") {
|
|
24
|
+
return { result: [] };
|
|
25
|
+
}
|
|
26
|
+
const coverage = await session.post("Profiler.takePreciseCoverage");
|
|
27
|
+
const result = [];
|
|
28
|
+
// Reduce amount of data sent over rpc by doing some early result filtering
|
|
29
|
+
for (const entry of coverage.result) {
|
|
30
|
+
if (filterResult(entry)) {
|
|
31
|
+
result.push({
|
|
32
|
+
...entry,
|
|
33
|
+
startOffset: options?.moduleExecutionInfo?.get(normalize(fileURLToPath(entry.url)))?.startOffset || 0
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { result };
|
|
38
|
+
},
|
|
39
|
+
async stopCoverage({ isolate }) {
|
|
40
|
+
if (isolate === false) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await session.post("Profiler.stopPreciseCoverage");
|
|
44
|
+
await session.post("Profiler.disable");
|
|
45
|
+
session.disconnect();
|
|
46
|
+
},
|
|
47
|
+
async getProvider() {
|
|
48
|
+
return loadProvider();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function filterResult(coverage) {
|
|
52
|
+
if (!coverage.url.startsWith("file://")) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (coverage.url.includes("/node_modules/")) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (coverage.url.includes("/@id/@vitest/")) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (coverage.url.includes("/@vite/client")) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { mod as default };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
2
|
+
function normalizeWindowsPath(input = "") {
|
|
3
|
+
if (!input) {
|
|
4
|
+
return input;
|
|
5
|
+
}
|
|
6
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const _UNC_REGEX = /^[/\\]{2}/;
|
|
10
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
11
|
+
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
12
|
+
const normalize = function(path) {
|
|
13
|
+
if (path.length === 0) {
|
|
14
|
+
return ".";
|
|
15
|
+
}
|
|
16
|
+
path = normalizeWindowsPath(path);
|
|
17
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
18
|
+
const isPathAbsolute = isAbsolute(path);
|
|
19
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
20
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
21
|
+
if (path.length === 0) {
|
|
22
|
+
if (isPathAbsolute) {
|
|
23
|
+
return "/";
|
|
24
|
+
}
|
|
25
|
+
return trailingSeparator ? "./" : ".";
|
|
26
|
+
}
|
|
27
|
+
if (trailingSeparator) {
|
|
28
|
+
path += "/";
|
|
29
|
+
}
|
|
30
|
+
if (_DRIVE_LETTER_RE.test(path)) {
|
|
31
|
+
path += "/";
|
|
32
|
+
}
|
|
33
|
+
if (isUNCPath) {
|
|
34
|
+
if (!isPathAbsolute) {
|
|
35
|
+
return `//./${path}`;
|
|
36
|
+
}
|
|
37
|
+
return `//${path}`;
|
|
38
|
+
}
|
|
39
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
40
|
+
};
|
|
41
|
+
function normalizeString(path, allowAboveRoot) {
|
|
42
|
+
let res = "";
|
|
43
|
+
let lastSegmentLength = 0;
|
|
44
|
+
let lastSlash = -1;
|
|
45
|
+
let dots = 0;
|
|
46
|
+
let char = null;
|
|
47
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
48
|
+
if (index < path.length) {
|
|
49
|
+
char = path[index];
|
|
50
|
+
} else if (char === "/") {
|
|
51
|
+
break;
|
|
52
|
+
} else {
|
|
53
|
+
char = "/";
|
|
54
|
+
}
|
|
55
|
+
if (char === "/") {
|
|
56
|
+
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
|
57
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
58
|
+
if (res.length > 2) {
|
|
59
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
60
|
+
if (lastSlashIndex === -1) {
|
|
61
|
+
res = "";
|
|
62
|
+
lastSegmentLength = 0;
|
|
63
|
+
} else {
|
|
64
|
+
res = res.slice(0, lastSlashIndex);
|
|
65
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
66
|
+
}
|
|
67
|
+
lastSlash = index;
|
|
68
|
+
dots = 0;
|
|
69
|
+
continue;
|
|
70
|
+
} else if (res.length > 0) {
|
|
71
|
+
res = "";
|
|
72
|
+
lastSegmentLength = 0;
|
|
73
|
+
lastSlash = index;
|
|
74
|
+
dots = 0;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (allowAboveRoot) {
|
|
79
|
+
res += res.length > 0 ? "/.." : "..";
|
|
80
|
+
lastSegmentLength = 2;
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
if (res.length > 0) {
|
|
84
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
85
|
+
} else {
|
|
86
|
+
res = path.slice(lastSlash + 1, index);
|
|
87
|
+
}
|
|
88
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
89
|
+
}
|
|
90
|
+
lastSlash = index;
|
|
91
|
+
dots = 0;
|
|
92
|
+
} else if (char === "." && dots !== -1) {
|
|
93
|
+
++dots;
|
|
94
|
+
} else {
|
|
95
|
+
dots = -1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return res;
|
|
99
|
+
}
|
|
100
|
+
const isAbsolute = function(p) {
|
|
101
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export { normalize as n };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CoverageMap } from 'istanbul-lib-coverage';
|
|
2
|
+
import { ProxifiedModule } from 'magicast';
|
|
3
|
+
import { Profiler } from 'node:inspector';
|
|
4
|
+
import { BaseCoverageProvider, ResolvedCoverageOptions, CoverageProvider, Vitest, ReportContext } from 'vitest/node';
|
|
5
|
+
|
|
6
|
+
interface ScriptCoverageWithOffset extends Profiler.ScriptCoverage {
|
|
7
|
+
startOffset: number;
|
|
8
|
+
}
|
|
9
|
+
declare class V8CoverageProvider extends BaseCoverageProvider<ResolvedCoverageOptions<"v8">> implements CoverageProvider {
|
|
10
|
+
name: "v8";
|
|
11
|
+
version: string;
|
|
12
|
+
initialize(ctx: Vitest): void;
|
|
13
|
+
createCoverageMap(): CoverageMap;
|
|
14
|
+
generateCoverage({ allTestsRun }: ReportContext): Promise<CoverageMap>;
|
|
15
|
+
generateReports(coverageMap: CoverageMap, allTestsRun?: boolean): Promise<void>;
|
|
16
|
+
parseConfigModule(configFilePath: string): Promise<ProxifiedModule<any>>;
|
|
17
|
+
private getCoverageMapForUncoveredFiles;
|
|
18
|
+
private remapCoverage;
|
|
19
|
+
private getSources;
|
|
20
|
+
private convertCoverage;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { V8CoverageProvider };
|
|
24
|
+
export type { ScriptCoverageWithOffset };
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { existsSync, promises } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { mergeProcessCovs } from '@bcoe/v8-coverage';
|
|
4
|
+
import astV8ToIstanbul from 'ast-v8-to-istanbul';
|
|
5
|
+
import libCoverage from 'istanbul-lib-coverage';
|
|
6
|
+
import libReport from 'istanbul-lib-report';
|
|
7
|
+
import reports from 'istanbul-reports';
|
|
8
|
+
import { parseModule } from 'magicast';
|
|
9
|
+
import { createDebug } from 'obug';
|
|
10
|
+
import { provider } from 'std-env';
|
|
11
|
+
import c from 'tinyrainbow';
|
|
12
|
+
import { BaseCoverageProvider, parseAstAsync } from 'vitest/node';
|
|
13
|
+
import { n as normalize } from './pathe.M-eThtNZ-BTaAGrLg.js';
|
|
14
|
+
|
|
15
|
+
var version = "4.1.0";
|
|
16
|
+
|
|
17
|
+
const FILE_PROTOCOL = "file://";
|
|
18
|
+
const debug = createDebug("vitest:coverage");
|
|
19
|
+
class V8CoverageProvider extends BaseCoverageProvider {
|
|
20
|
+
name = "v8";
|
|
21
|
+
version = version;
|
|
22
|
+
initialize(ctx) {
|
|
23
|
+
this._initialize(ctx);
|
|
24
|
+
}
|
|
25
|
+
createCoverageMap() {
|
|
26
|
+
return libCoverage.createCoverageMap({});
|
|
27
|
+
}
|
|
28
|
+
async generateCoverage({ allTestsRun }) {
|
|
29
|
+
const start = debug.enabled ? performance.now() : 0;
|
|
30
|
+
const coverageMap = this.createCoverageMap();
|
|
31
|
+
let merged = { result: [] };
|
|
32
|
+
await this.readCoverageFiles({
|
|
33
|
+
onFileRead(coverage) {
|
|
34
|
+
merged = mergeProcessCovs([merged, coverage]);
|
|
35
|
+
// mergeProcessCovs sometimes loses startOffset, e.g. in vue
|
|
36
|
+
merged.result.forEach((result) => {
|
|
37
|
+
if (!result.startOffset) {
|
|
38
|
+
const original = coverage.result.find((r) => r.url === result.url);
|
|
39
|
+
result.startOffset = original?.startOffset || 0;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
onFinished: async (project, environment) => {
|
|
44
|
+
// Source maps can change based on projectName and transform mode.
|
|
45
|
+
// Coverage transform re-uses source maps so we need to separate transforms from each other.
|
|
46
|
+
const converted = await this.convertCoverage(merged, project, environment);
|
|
47
|
+
coverageMap.merge(converted);
|
|
48
|
+
merged = { result: [] };
|
|
49
|
+
},
|
|
50
|
+
onDebug: debug
|
|
51
|
+
});
|
|
52
|
+
// Include untested files when all tests were run (not a single file re-run)
|
|
53
|
+
// or if previous results are preserved by "cleanOnRerun: false"
|
|
54
|
+
if (this.options.include != null && (allTestsRun || !this.options.cleanOnRerun)) {
|
|
55
|
+
const coveredFiles = coverageMap.files();
|
|
56
|
+
const untestedCoverage = await this.getCoverageMapForUncoveredFiles(coveredFiles);
|
|
57
|
+
coverageMap.merge(untestedCoverage);
|
|
58
|
+
}
|
|
59
|
+
coverageMap.filter((filename) => {
|
|
60
|
+
const exists = existsSync(filename);
|
|
61
|
+
if (this.options.excludeAfterRemap) {
|
|
62
|
+
return exists && this.isIncluded(filename);
|
|
63
|
+
}
|
|
64
|
+
return exists;
|
|
65
|
+
});
|
|
66
|
+
if (debug.enabled) {
|
|
67
|
+
debug(`Generate coverage total time ${(performance.now() - start).toFixed()} ms`);
|
|
68
|
+
}
|
|
69
|
+
return coverageMap;
|
|
70
|
+
}
|
|
71
|
+
async generateReports(coverageMap, allTestsRun) {
|
|
72
|
+
if (provider === "stackblitz") {
|
|
73
|
+
this.ctx.logger.log(c.blue(" % ") + c.yellow("@vitest/coverage-v8 does not work on Stackblitz. Report will be empty."));
|
|
74
|
+
}
|
|
75
|
+
const context = libReport.createContext({
|
|
76
|
+
dir: this.options.reportsDirectory,
|
|
77
|
+
coverageMap,
|
|
78
|
+
watermarks: this.options.watermarks
|
|
79
|
+
});
|
|
80
|
+
if (this.hasTerminalReporter(this.options.reporter)) {
|
|
81
|
+
this.ctx.logger.log(c.blue(" % ") + c.dim("Coverage report from ") + c.yellow(this.name));
|
|
82
|
+
}
|
|
83
|
+
for (const reporter of this.options.reporter) {
|
|
84
|
+
// Type assertion required for custom reporters
|
|
85
|
+
reports.create(reporter[0], {
|
|
86
|
+
skipFull: this.options.skipFull,
|
|
87
|
+
projectRoot: this.ctx.config.root,
|
|
88
|
+
...reporter[1]
|
|
89
|
+
}).execute(context);
|
|
90
|
+
}
|
|
91
|
+
if (this.options.thresholds) {
|
|
92
|
+
await this.reportThresholds(coverageMap, allTestsRun);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async parseConfigModule(configFilePath) {
|
|
96
|
+
const contents = await promises.readFile(configFilePath, "utf8");
|
|
97
|
+
return parseModule(`${contents}${this.autoUpdateMarker}`);
|
|
98
|
+
}
|
|
99
|
+
async getCoverageMapForUncoveredFiles(testedFiles) {
|
|
100
|
+
const transform = this.createUncoveredFileTransformer(this.ctx);
|
|
101
|
+
const uncoveredFiles = await this.getUntestedFiles(testedFiles);
|
|
102
|
+
let index = 0;
|
|
103
|
+
const coverageMap = this.createCoverageMap();
|
|
104
|
+
for (const chunk of this.toSlices(uncoveredFiles, this.options.processingConcurrency)) {
|
|
105
|
+
if (debug.enabled) {
|
|
106
|
+
index += chunk.length;
|
|
107
|
+
debug("Uncovered files %d/%d", index, uncoveredFiles.length);
|
|
108
|
+
}
|
|
109
|
+
await Promise.all(chunk.map(async (filename) => {
|
|
110
|
+
let timeout;
|
|
111
|
+
let start;
|
|
112
|
+
if (debug.enabled) {
|
|
113
|
+
start = performance.now();
|
|
114
|
+
timeout = setTimeout(() => debug(c.bgRed(`File "${filename}" is taking longer than 3s`)), 3e3);
|
|
115
|
+
}
|
|
116
|
+
// Do not use pathToFileURL to avoid encoding filename parts
|
|
117
|
+
const url = `file://${filename[0] === "/" ? "" : "/"}${filename}`;
|
|
118
|
+
const sources = await this.getSources(url, transform);
|
|
119
|
+
coverageMap.merge(await this.remapCoverage(url, 0, sources, []));
|
|
120
|
+
if (debug.enabled) {
|
|
121
|
+
clearTimeout(timeout);
|
|
122
|
+
const diff = performance.now() - start;
|
|
123
|
+
const color = diff > 500 ? c.bgRed : c.bgGreen;
|
|
124
|
+
debug(`${color(` ${diff.toFixed()} ms `)} ${filename}`);
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
return coverageMap;
|
|
129
|
+
}
|
|
130
|
+
async remapCoverage(filename, wrapperLength, result, functions) {
|
|
131
|
+
let ast;
|
|
132
|
+
try {
|
|
133
|
+
ast = await parseAstAsync(result.code);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
this.ctx.logger.error(`Failed to parse ${filename}. Excluding it from coverage.\n`, error);
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
return await astV8ToIstanbul({
|
|
139
|
+
code: result.code,
|
|
140
|
+
sourceMap: result.map,
|
|
141
|
+
ast,
|
|
142
|
+
coverage: {
|
|
143
|
+
functions,
|
|
144
|
+
url: filename
|
|
145
|
+
},
|
|
146
|
+
ignoreClassMethods: this.options.ignoreClassMethods,
|
|
147
|
+
wrapperLength,
|
|
148
|
+
ignoreNode: (node, type) => {
|
|
149
|
+
// SSR transformed imports
|
|
150
|
+
if (type === "statement" && node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.id.name.startsWith("__vite_ssr_import_")) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
// SSR transformed exports vite@>6.3.5
|
|
154
|
+
if (type === "statement" && node.type === "ExpressionStatement" && node.expression.type === "AssignmentExpression" && node.expression.left.type === "MemberExpression" && node.expression.left.object.type === "Identifier" && node.expression.left.object.name === "__vite_ssr_exports__") {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
// SSR transformed exports vite@^6.3.5
|
|
158
|
+
if (type === "statement" && node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.id.name === "__vite_ssr_export_default__") {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
// CJS imports as ternaries - e.g.
|
|
162
|
+
// const React = __vite__cjsImport0_react.__esModule ? __vite__cjsImport0_react.default : __vite__cjsImport0_react;
|
|
163
|
+
if (type === "branch" && node.type === "ConditionalExpression" && node.test.type === "MemberExpression" && node.test.object.type === "Identifier" && node.test.object.name.startsWith("__vite__cjsImport") && node.test.property.type === "Identifier" && node.test.property.name === "__esModule") {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
// in-source test with "if (import.meta.vitest)"
|
|
167
|
+
if ((type === "branch" || type === "statement") && node.type === "IfStatement" && node.test.type === "MemberExpression" && node.test.property.type === "Identifier" && node.test.property.name === "vitest") {
|
|
168
|
+
// SSR
|
|
169
|
+
if (node.test.object.type === "Identifier" && node.test.object.name === "__vite_ssr_import_meta__") {
|
|
170
|
+
return "ignore-this-and-nested-nodes";
|
|
171
|
+
}
|
|
172
|
+
// Web
|
|
173
|
+
if (node.test.object.type === "MetaProperty" && node.test.object.meta.name === "import" && node.test.object.property.name === "meta") {
|
|
174
|
+
return "ignore-this-and-nested-nodes";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Browser mode's "import.meta.env ="
|
|
178
|
+
if (type === "statement" && node.type === "ExpressionStatement" && node.expression.type === "AssignmentExpression" && node.expression.left.type === "MemberExpression" && node.expression.left.object.type === "MetaProperty" && node.expression.left.object.meta.name === "import" && node.expression.left.object.property.name === "meta" && node.expression.left.property.type === "Identifier" && node.expression.left.property.name === "env") {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
// SSR mode's "import.meta.env ="
|
|
182
|
+
if (type === "statement" && node.type === "ExpressionStatement" && node.expression.type === "AssignmentExpression" && node.expression.left.type === "MemberExpression" && node.expression.left.object.type === "Identifier" && node.expression.left.object.name === "__vite_ssr_import_meta__") {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
// SWC's decorators
|
|
186
|
+
if (type === "statement" && node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" && node.expression.callee.name === "_ts_decorate") {
|
|
187
|
+
return "ignore-this-and-nested-nodes";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async getSources(url, onTransform, functions = []) {
|
|
193
|
+
// TODO: need to standardize file urls before this call somehow, this is messy
|
|
194
|
+
const filepath = url.match(/^file:\/\/\/\w:\//) ? url.slice(8) : removeStartsWith(url, FILE_PROTOCOL);
|
|
195
|
+
// TODO: do we still need to "catch" here? why would it fail?
|
|
196
|
+
const transformResult = await onTransform(filepath).catch(() => null);
|
|
197
|
+
const map = transformResult?.map;
|
|
198
|
+
const code = transformResult?.code;
|
|
199
|
+
if (code == null) {
|
|
200
|
+
const filePath = normalize(fileURLToPath(url));
|
|
201
|
+
const original = await promises.readFile(filePath, "utf-8").catch(() => {
|
|
202
|
+
// If file does not exist construct a dummy source for it.
|
|
203
|
+
// These can be files that were generated dynamically during the test run and were removed after it.
|
|
204
|
+
const length = findLongestFunctionLength(functions);
|
|
205
|
+
return "/".repeat(length);
|
|
206
|
+
});
|
|
207
|
+
return { code: original };
|
|
208
|
+
}
|
|
209
|
+
// Vue needs special handling for "map.sources"
|
|
210
|
+
if (map) {
|
|
211
|
+
map.sources ||= [];
|
|
212
|
+
map.sources = map.sources.filter((source) => source != null).map((source) => new URL(source, url).href);
|
|
213
|
+
if (map.sources.length === 0) {
|
|
214
|
+
map.sources.push(url);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
code,
|
|
219
|
+
map
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
async convertCoverage(coverage, project = this.ctx.getRootProject(), environment) {
|
|
223
|
+
if (environment === "__browser__" && !project.browser) {
|
|
224
|
+
throw new Error(`Cannot access browser module graph because it was torn down.`);
|
|
225
|
+
}
|
|
226
|
+
const onTransform = async (filepath) => {
|
|
227
|
+
const result = await this.transformFile(filepath, project, environment);
|
|
228
|
+
if (result && environment === "__browser__" && project.browser) {
|
|
229
|
+
return {
|
|
230
|
+
...result,
|
|
231
|
+
code: `${result.code}// <inline-source-map>`
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
};
|
|
236
|
+
const scriptCoverages = [];
|
|
237
|
+
for (const result of coverage.result) {
|
|
238
|
+
if (environment === "__browser__") {
|
|
239
|
+
if (result.url.startsWith("/@fs")) {
|
|
240
|
+
result.url = `${FILE_PROTOCOL}${removeStartsWith(result.url, "/@fs")}`;
|
|
241
|
+
} else if (result.url.startsWith(project.config.root)) {
|
|
242
|
+
result.url = `${FILE_PROTOCOL}${result.url}`;
|
|
243
|
+
} else {
|
|
244
|
+
result.url = `${FILE_PROTOCOL}${project.config.root}${result.url}`;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (this.isIncluded(fileURLToPath(result.url))) {
|
|
248
|
+
scriptCoverages.push({
|
|
249
|
+
...result,
|
|
250
|
+
url: decodeURIComponent(result.url)
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const coverageMap = this.createCoverageMap();
|
|
255
|
+
let index = 0;
|
|
256
|
+
for (const chunk of this.toSlices(scriptCoverages, this.options.processingConcurrency)) {
|
|
257
|
+
if (debug.enabled) {
|
|
258
|
+
index += chunk.length;
|
|
259
|
+
debug("Converting %d/%d", index, scriptCoverages.length);
|
|
260
|
+
}
|
|
261
|
+
await Promise.all(chunk.map(async ({ url, functions, startOffset }) => {
|
|
262
|
+
let timeout;
|
|
263
|
+
let start;
|
|
264
|
+
if (debug.enabled) {
|
|
265
|
+
start = performance.now();
|
|
266
|
+
timeout = setTimeout(() => debug(c.bgRed(`File "${fileURLToPath(url)}" is taking longer than 3s`)), 3e3);
|
|
267
|
+
}
|
|
268
|
+
const sources = await this.getSources(url, onTransform, functions);
|
|
269
|
+
coverageMap.merge(await this.remapCoverage(url, startOffset, sources, functions));
|
|
270
|
+
if (debug.enabled) {
|
|
271
|
+
clearTimeout(timeout);
|
|
272
|
+
const diff = performance.now() - start;
|
|
273
|
+
const color = diff > 500 ? c.bgRed : c.bgGreen;
|
|
274
|
+
debug(`${color(` ${diff.toFixed()} ms `)} ${fileURLToPath(url)}`);
|
|
275
|
+
}
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
return coverageMap;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Find the function with highest `endOffset` to determine the length of the file
|
|
283
|
+
*/
|
|
284
|
+
function findLongestFunctionLength(functions) {
|
|
285
|
+
return functions.reduce((previous, current) => {
|
|
286
|
+
const maxEndOffset = current.ranges.reduce((endOffset, range) => Math.max(endOffset, range.endOffset), 0);
|
|
287
|
+
return Math.max(previous, maxEndOffset);
|
|
288
|
+
}, 0);
|
|
289
|
+
}
|
|
290
|
+
function removeStartsWith(filepath, start) {
|
|
291
|
+
if (filepath.startsWith(start)) {
|
|
292
|
+
return filepath.slice(start.length);
|
|
293
|
+
}
|
|
294
|
+
return filepath;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { V8CoverageProvider };
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/vitest__coverage-v8",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "4.1.0-depup.0",
|
|
5
|
+
"description": "[DepUp] V8 coverage provider for Vitest",
|
|
6
|
+
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"funding": "https://opencollective.com/vitest",
|
|
9
|
+
"homepage": "https://vitest.dev/guide/coverage",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/vitest-dev/vitest.git",
|
|
13
|
+
"directory": "packages/coverage-v8"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/vitest-dev/vitest/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"depup",
|
|
20
|
+
"dependency-bumped",
|
|
21
|
+
"updated-deps",
|
|
22
|
+
"@vitest/coverage-v8",
|
|
23
|
+
"vite",
|
|
24
|
+
"vitest",
|
|
25
|
+
"test",
|
|
26
|
+
"coverage",
|
|
27
|
+
"v8"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./browser": {
|
|
36
|
+
"types": "./dist/browser.d.ts",
|
|
37
|
+
"default": "./dist/browser.js"
|
|
38
|
+
},
|
|
39
|
+
"./*": "./*"
|
|
40
|
+
},
|
|
41
|
+
"main": "./dist/index.js",
|
|
42
|
+
"module": "./dist/index.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"changes.json",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@vitest/browser": "4.1.0",
|
|
51
|
+
"vitest": "4.1.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@vitest/browser": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@bcoe/v8-coverage": "^1.0.2",
|
|
60
|
+
"ast-v8-to-istanbul": "^1.0.0",
|
|
61
|
+
"istanbul-lib-coverage": "^3.2.2",
|
|
62
|
+
"istanbul-lib-report": "^3.0.1",
|
|
63
|
+
"istanbul-reports": "^3.2.0",
|
|
64
|
+
"magicast": "^0.5.2",
|
|
65
|
+
"obug": "^2.1.1",
|
|
66
|
+
"std-env": "^4.0.0-rc.1",
|
|
67
|
+
"tinyrainbow": "^3.1.0",
|
|
68
|
+
"@vitest/utils": "4.1.0"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/istanbul-lib-coverage": "^2.0.6",
|
|
72
|
+
"@types/istanbul-lib-report": "^3.0.3",
|
|
73
|
+
"@types/istanbul-reports": "^3.0.4",
|
|
74
|
+
"pathe": "^2.0.3",
|
|
75
|
+
"vitest": "4.1.0",
|
|
76
|
+
"@vitest/browser-playwright": "4.1.0",
|
|
77
|
+
"@vitest/browser": "4.1.0"
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"build": "premove dist && rollup -c",
|
|
81
|
+
"dev": "rollup -c --watch --watch.include 'src/**'"
|
|
82
|
+
},
|
|
83
|
+
"depup": {
|
|
84
|
+
"changes": {
|
|
85
|
+
"tinyrainbow": {
|
|
86
|
+
"from": "^3.0.3",
|
|
87
|
+
"to": "^3.1.0"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"depsUpdated": 1,
|
|
91
|
+
"originalPackage": "@vitest/coverage-v8",
|
|
92
|
+
"originalVersion": "4.1.0",
|
|
93
|
+
"processedAt": "2026-03-17T16:33:59.211Z",
|
|
94
|
+
"smokeTest": "passed"
|
|
95
|
+
}
|
|
96
|
+
}
|