@vitest/coverage-v8 3.2.4 → 4.0.0-beta.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021-Present Vitest Team
3
+ Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import inspector from 'node:inspector';
1
+ import inspector from 'node:inspector/promises';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { provider } from 'std-env';
4
4
  import { l as loadProvider } from './load-provider-CdgAx3rL.js';
5
+ import { n as normalize } from './pathe.M-eThtNZ-BTaAGrLg.js';
5
6
 
6
7
  const session = new inspector.Session();
7
8
  let enabled = false;
@@ -12,39 +13,35 @@ const mod = {
12
13
  }
13
14
  enabled = true;
14
15
  session.connect();
15
- await new Promise((resolve) => session.post("Profiler.enable", resolve));
16
- await new Promise((resolve) => session.post("Profiler.startPreciseCoverage", {
16
+ await session.post("Profiler.enable");
17
+ await session.post("Profiler.startPreciseCoverage", {
17
18
  callCount: true,
18
19
  detailed: true
19
- }, resolve));
20
+ });
20
21
  },
21
- takeCoverage(options) {
22
- return new Promise((resolve, reject) => {
23
- session.post("Profiler.takePreciseCoverage", async (error, coverage) => {
24
- if (error) {
25
- return reject(error);
26
- }
27
- try {
28
- const result = coverage.result.filter(filterResult).map((res) => ({
29
- ...res,
30
- startOffset: options?.moduleExecutionInfo?.get(fileURLToPath(res.url))?.startOffset || 0
31
- }));
32
- resolve({ result });
33
- } catch (e) {
34
- reject(e);
35
- }
36
- });
37
- if (provider === "stackblitz") {
38
- resolve({ result: [] });
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
+ });
39
35
  }
40
- });
36
+ }
37
+ return { result };
41
38
  },
42
39
  async stopCoverage({ isolate }) {
43
40
  if (isolate === false) {
44
41
  return;
45
42
  }
46
- await new Promise((resolve) => session.post("Profiler.stopPreciseCoverage", resolve));
47
- await new Promise((resolve) => session.post("Profiler.disable", resolve));
43
+ await session.post("Profiler.stopPreciseCoverage");
44
+ await session.post("Profiler.disable");
48
45
  session.disconnect();
49
46
  },
50
47
  async getProvider() {
@@ -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 };
@@ -2,7 +2,6 @@ import { CoverageMap } from 'istanbul-lib-coverage';
2
2
  import { ProxifiedModule } from 'magicast';
3
3
  import { Profiler } from 'node:inspector';
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
  interface ScriptCoverageWithOffset extends Profiler.ScriptCoverage {
@@ -11,14 +10,13 @@ interface ScriptCoverageWithOffset extends Profiler.ScriptCoverage {
11
10
  declare class V8CoverageProvider extends BaseCoverageProvider<ResolvedCoverageOptions<"v8">> implements CoverageProvider {
12
11
  name: "v8";
13
12
  version: string;
14
- testExclude: InstanceType<typeof TestExclude>;
15
13
  initialize(ctx: Vitest): void;
16
14
  createCoverageMap(): CoverageMap;
17
15
  generateCoverage({ allTestsRun }: ReportContext): Promise<CoverageMap>;
18
16
  generateReports(coverageMap: CoverageMap, allTestsRun?: boolean): Promise<void>;
19
17
  parseConfigModule(configFilePath: string): Promise<ProxifiedModule<any>>;
20
- private getUntestedFiles;
21
- private v8ToIstanbul;
18
+ private getCoverageMapForUncoveredFiles;
19
+ private remapCoverage;
22
20
  private getSources;
23
21
  private convertCoverage;
24
22
  }