@vitest/coverage-v8 0.32.1 → 0.32.3

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.
Files changed (2) hide show
  1. package/dist/provider.js +17 -8
  2. package/package.json +5 -5
package/dist/provider.js CHANGED
@@ -143,11 +143,11 @@ const isAbsolute = function(p) {
143
143
  const WRAPPER_LENGTH = 185;
144
144
  const VITE_EXPORTS_LINE_PATTERN = /Object\.defineProperty\(__vite_ssr_exports__.*\n/g;
145
145
  class V8CoverageProvider extends BaseCoverageProvider {
146
- constructor() {
147
- super(...arguments);
148
- this.name = "v8";
149
- this.coverages = [];
150
- }
146
+ name = "v8";
147
+ ctx;
148
+ options;
149
+ testExclude;
150
+ coverages = [];
151
151
  initialize(ctx) {
152
152
  const config = ctx.config.coverage;
153
153
  this.ctx = ctx;
@@ -194,7 +194,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
194
194
  scriptCoverages.push(...untestedFiles);
195
195
  }
196
196
  const converted = await Promise.all(scriptCoverages.map(async ({ url, functions }) => {
197
- const sources = await this.getSources(url);
197
+ const sources = await this.getSources(url, functions);
198
198
  const wrapperLength = sources.sourceMap ? WRAPPER_LENGTH : 0;
199
199
  const converter = v8ToIstanbul(url, wrapperLength, sources);
200
200
  await converter.load();
@@ -269,7 +269,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
269
269
  };
270
270
  }));
271
271
  }
272
- async getSources(url) {
272
+ async getSources(url, functions = []) {
273
273
  var _a;
274
274
  const filePath = normalize(fileURLToPath(url));
275
275
  const transformResult = this.ctx.projects.map((project) => {
@@ -278,7 +278,10 @@ class V8CoverageProvider extends BaseCoverageProvider {
278
278
  }).filter(Boolean).shift();
279
279
  const map = transformResult == null ? void 0 : transformResult.map;
280
280
  const code = transformResult == null ? void 0 : transformResult.code;
281
- const sourcesContent = ((_a = map == null ? void 0 : map.sourcesContent) == null ? void 0 : _a[0]) || await promises.readFile(filePath, "utf-8");
281
+ const sourcesContent = ((_a = map == null ? void 0 : map.sourcesContent) == null ? void 0 : _a[0]) || await promises.readFile(filePath, "utf-8").catch(() => {
282
+ const length = findLongestFunctionLength(functions);
283
+ return ".".repeat(length);
284
+ });
282
285
  if (!map)
283
286
  return { source: code || sourcesContent };
284
287
  return {
@@ -309,5 +312,11 @@ function removeViteHelpersFromSourceMaps(source, map) {
309
312
  );
310
313
  return combinedMap;
311
314
  }
315
+ function findLongestFunctionLength(functions) {
316
+ return functions.reduce((previous, current) => {
317
+ const maxEndOffset = current.ranges.reduce((endOffset, range) => Math.max(endOffset, range.endOffset), 0);
318
+ return Math.max(previous, maxEndOffset);
319
+ }, 0);
320
+ }
312
321
 
313
322
  export { V8CoverageProvider };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/coverage-v8",
3
3
  "type": "module",
4
- "version": "0.32.1",
4
+ "version": "0.32.3",
5
5
  "description": "V8 coverage provider for Vitest",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  "istanbul-reports": "^3.1.5",
49
49
  "magic-string": "^0.30.0",
50
50
  "picocolors": "^1.0.0",
51
- "std-env": "^3.3.2",
51
+ "std-env": "^3.3.3",
52
52
  "test-exclude": "^6.0.0",
53
53
  "v8-to-istanbul": "^9.1.0"
54
54
  },
@@ -57,9 +57,9 @@
57
57
  "@types/istanbul-lib-report": "^3.0.0",
58
58
  "@types/istanbul-lib-source-maps": "^4.0.1",
59
59
  "@types/istanbul-reports": "^3.0.1",
60
- "pathe": "^1.1.0",
61
- "vitest": "0.32.1",
62
- "vite-node": "0.32.1"
60
+ "pathe": "^1.1.1",
61
+ "vite-node": "0.32.3",
62
+ "vitest": "0.32.3"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "rimraf dist && rollup -c",