@vitest/coverage-istanbul 3.2.4 → 4.0.0-beta.2

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.
@@ -2,14 +2,12 @@ import libCoverage, { CoverageMap } from 'istanbul-lib-coverage';
2
2
  import { Instrumenter } from 'istanbul-lib-instrument';
3
3
  import { ProxifiedModule } from 'magicast';
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
  declare class IstanbulCoverageProvider extends BaseCoverageProvider<ResolvedCoverageOptions<"istanbul">> implements CoverageProvider {
9
8
  name: "istanbul";
10
9
  version: string;
11
10
  instrumenter: Instrumenter;
12
- testExclude: InstanceType<typeof TestExclude>;
13
11
  initialize(ctx: Vitest): void;
14
12
  onFileTransform(sourceCode: string, id: string, pluginCtx: any): {
15
13
  code: string
package/dist/provider.js CHANGED
@@ -7,125 +7,20 @@ import libReport from 'istanbul-lib-report';
7
7
  import libSourceMaps from 'istanbul-lib-source-maps';
8
8
  import reports from 'istanbul-reports';
9
9
  import { parseModule } from 'magicast';
10
- import TestExclude from 'test-exclude';
11
10
  import c from 'tinyrainbow';
12
11
  import { BaseCoverageProvider } from 'vitest/coverage';
13
12
  import { isCSSRequest } from 'vitest/node';
14
13
  import { C as COVERAGE_STORE_KEY } from './constants-BCJfMgEg.js';
15
14
 
16
- const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
17
- function normalizeWindowsPath(input = "") {
18
- if (!input) {
19
- return input;
20
- }
21
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
22
- }
23
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
24
- function cwd() {
25
- if (typeof process !== "undefined" && typeof process.cwd === "function") {
26
- return process.cwd().replace(/\\/g, "/");
27
- }
28
- return "/";
29
- }
30
- const resolve = function(...arguments_) {
31
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
32
- let resolvedPath = "";
33
- let resolvedAbsolute = false;
34
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
35
- const path = index >= 0 ? arguments_[index] : cwd();
36
- if (!path || path.length === 0) {
37
- continue;
38
- }
39
- resolvedPath = `${path}/${resolvedPath}`;
40
- resolvedAbsolute = isAbsolute(path);
41
- }
42
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
43
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
44
- return `/${resolvedPath}`;
45
- }
46
- return resolvedPath.length > 0 ? resolvedPath : ".";
47
- };
48
- function normalizeString(path, allowAboveRoot) {
49
- let res = "";
50
- let lastSegmentLength = 0;
51
- let lastSlash = -1;
52
- let dots = 0;
53
- let char = null;
54
- for (let index = 0; index <= path.length; ++index) {
55
- if (index < path.length) {
56
- char = path[index];
57
- } else if (char === "/") {
58
- break;
59
- } else {
60
- char = "/";
61
- }
62
- if (char === "/") {
63
- if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
64
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
65
- if (res.length > 2) {
66
- const lastSlashIndex = res.lastIndexOf("/");
67
- if (lastSlashIndex === -1) {
68
- res = "";
69
- lastSegmentLength = 0;
70
- } else {
71
- res = res.slice(0, lastSlashIndex);
72
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
73
- }
74
- lastSlash = index;
75
- dots = 0;
76
- continue;
77
- } else if (res.length > 0) {
78
- res = "";
79
- lastSegmentLength = 0;
80
- lastSlash = index;
81
- dots = 0;
82
- continue;
83
- }
84
- }
85
- if (allowAboveRoot) {
86
- res += res.length > 0 ? "/.." : "..";
87
- lastSegmentLength = 2;
88
- }
89
- } else {
90
- if (res.length > 0) {
91
- res += `/${path.slice(lastSlash + 1, index)}`;
92
- } else {
93
- res = path.slice(lastSlash + 1, index);
94
- }
95
- lastSegmentLength = index - lastSlash - 1;
96
- }
97
- lastSlash = index;
98
- dots = 0;
99
- } else if (char === "." && dots !== -1) {
100
- ++dots;
101
- } else {
102
- dots = -1;
103
- }
104
- }
105
- return res;
106
- }
107
- const isAbsolute = function(p) {
108
- return _IS_ABSOLUTE_RE.test(p);
109
- };
110
-
111
- var version = "3.2.4";
15
+ var version = "4.0.0-beta.2";
112
16
 
113
17
  const debug = createDebug("vitest:coverage");
114
18
  class IstanbulCoverageProvider extends BaseCoverageProvider {
115
19
  name = "istanbul";
116
20
  version = version;
117
21
  instrumenter;
118
- testExclude;
119
22
  initialize(ctx) {
120
23
  this._initialize(ctx);
121
- this.testExclude = new TestExclude({
122
- cwd: ctx.config.root,
123
- include: this.options.include,
124
- exclude: this.options.exclude,
125
- excludeNodeModules: true,
126
- extension: this.options.extension,
127
- relativePath: !this.options.allowExternal
128
- });
129
24
  this.instrumenter = createInstrumenter({
130
25
  produceSourceMap: true,
131
26
  autoWrap: false,
@@ -146,7 +41,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
146
41
  if (isCSSRequest(id)) {
147
42
  return;
148
43
  }
149
- if (!this.testExclude.shouldInstrument(removeQueryParameters(id))) {
44
+ if (!this.isIncluded(removeQueryParameters(id))) {
150
45
  return;
151
46
  }
152
47
  const sourceMap = pluginCtx.getCombinedSourcemap();
@@ -181,13 +76,13 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
181
76
  });
182
77
  // Include untested files when all tests were run (not a single file re-run)
183
78
  // or if previous results are preserved by "cleanOnRerun: false"
184
- if (this.options.all && (allTestsRun || !this.options.cleanOnRerun)) {
79
+ if (this.options.include != null && (allTestsRun || !this.options.cleanOnRerun)) {
185
80
  const coveredFiles = coverageMap.files();
186
81
  const uncoveredCoverage = await this.getCoverageMapForUncoveredFiles(coveredFiles);
187
82
  coverageMap.merge(await transformCoverage(uncoveredCoverage));
188
83
  }
189
84
  if (this.options.excludeAfterRemap) {
190
- coverageMap.filter((filename) => this.testExclude.shouldInstrument(filename));
85
+ coverageMap.filter((filename) => this.isIncluded(filename));
191
86
  }
192
87
  if (debug.enabled) {
193
88
  debug("Generate coverage total time %d ms", (performance.now() - start).toFixed());
@@ -219,12 +114,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
219
114
  return parseModule(await promises.readFile(configFilePath, "utf8"));
220
115
  }
221
116
  async getCoverageMapForUncoveredFiles(coveredFiles) {
222
- const allFiles = await this.testExclude.glob(this.ctx.config.root);
223
- let includedFiles = allFiles.map((file) => resolve(this.ctx.config.root, file));
224
- if (this.ctx.config.changed) {
225
- includedFiles = (this.ctx.config.related || []).filter((file) => includedFiles.includes(file));
226
- }
227
- const uncoveredFiles = includedFiles.filter((file) => !coveredFiles.includes(file)).sort();
117
+ const uncoveredFiles = await this.getUntestedFiles(coveredFiles);
228
118
  const cacheKey = new Date().getTime();
229
119
  const coverageMap = this.createCoverageMap();
230
120
  const transform = this.createUncoveredFileTransformer(this.ctx);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/coverage-istanbul",
3
3
  "type": "module",
4
- "version": "3.2.4",
4
+ "version": "4.0.0-beta.2",
5
5
  "description": "Istanbul 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": "3.2.4"
40
+ "vitest": "4.0.0-beta.2"
41
41
  },
42
42
  "dependencies": {
43
43
  "@istanbuljs/schema": "^0.1.3",
@@ -48,7 +48,6 @@
48
48
  "istanbul-lib-source-maps": "^5.0.6",
49
49
  "istanbul-reports": "^3.1.7",
50
50
  "magicast": "^0.3.5",
51
- "test-exclude": "^7.0.1",
52
51
  "tinyrainbow": "^2.0.0"
53
52
  },
54
53
  "devDependencies": {
@@ -58,9 +57,8 @@
58
57
  "@types/istanbul-lib-report": "^3.0.3",
59
58
  "@types/istanbul-lib-source-maps": "^4.0.4",
60
59
  "@types/istanbul-reports": "^3.0.4",
61
- "@types/test-exclude": "^6.0.2",
62
60
  "pathe": "^2.0.3",
63
- "vitest": "3.2.4"
61
+ "vitest": "4.0.0-beta.2"
64
62
  },
65
63
  "scripts": {
66
64
  "build": "rimraf dist && rollup -c",