@vitest/coverage-v8 1.2.2 → 1.3.1

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,7 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021-Present Anthony Fu <https://github.com/antfu>
4
- Copyright (c) 2021-Present Matias Capeletto <https://github.com/patak-dev>
3
+ Copyright (c) 2021-Present Vitest Team
5
4
 
6
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
6
  of this software and associated documentation files (the "Software"), to deal
@@ -11,8 +11,8 @@ interface TestExclude {
11
11
  excludeNodeModules?: boolean;
12
12
  relativePath?: boolean;
13
13
  }): {
14
- shouldInstrument(filePath: string): boolean;
15
- glob(cwd: string): Promise<string[]>;
14
+ shouldInstrument: (filePath: string) => boolean;
15
+ glob: (cwd: string) => Promise<string[]>;
16
16
  };
17
17
  }
18
18
  type Options = ResolvedCoverageOptions<'v8'>;
package/dist/provider.js CHANGED
@@ -170,6 +170,7 @@ function cleanUrl(url) {
170
170
 
171
171
  const WRAPPER_LENGTH = 185;
172
172
  const VITE_EXPORTS_LINE_PATTERN = /Object\.defineProperty\(__vite_ssr_exports__.*\n/g;
173
+ const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes"(\s|.)+?]\),/g;
173
174
  const DEFAULT_PROJECT = Symbol.for("default-project");
174
175
  const debug = createDebug("vitest:coverage");
175
176
  let uniqueId = 0;
@@ -208,7 +209,9 @@ class V8CoverageProvider extends BaseCoverageProvider {
208
209
  extension: this.options.extension,
209
210
  relativePath: !this.options.allowExternal
210
211
  });
211
- this.coverageFilesDirectory = resolve(this.options.reportsDirectory, ".tmp");
212
+ const shard = this.ctx.config.shard;
213
+ const tempDirectory = `.tmp${shard ? `-${shard.index}-${shard.count}` : ""}`;
214
+ this.coverageFilesDirectory = resolve(this.options.reportsDirectory, tempDirectory);
212
215
  }
213
216
  resolveOptions() {
214
217
  return this.options;
@@ -251,7 +254,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
251
254
  for (const [projectName, coveragePerProject] of this.coverageFiles.entries()) {
252
255
  for (const [transformMode, filenames] of Object.entries(coveragePerProject)) {
253
256
  let merged = { result: [] };
254
- for (const chunk of toSlices(filenames, this.options.processingConcurrency)) {
257
+ for (const chunk of this.toSlices(filenames, this.options.processingConcurrency)) {
255
258
  if (debug.enabled) {
256
259
  index += chunk.length;
257
260
  debug("Covered files %d/%d", index, total);
@@ -278,7 +281,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
278
281
  coverageMap,
279
282
  watermarks: this.options.watermarks
280
283
  });
281
- if (hasTerminalReporter(this.options.reporter))
284
+ if (this.hasTerminalReporter(this.options.reporter))
282
285
  this.ctx.logger.log(c.blue(" % ") + c.dim("Coverage report from ") + c.yellow(this.name));
283
286
  for (const reporter of this.options.reporter) {
284
287
  reports.create(reporter[0], {
@@ -305,10 +308,8 @@ class V8CoverageProvider extends BaseCoverageProvider {
305
308
  this.updateThresholds({
306
309
  thresholds: resolvedThresholds,
307
310
  perFile: this.options.thresholds.perFile,
308
- configurationFile: {
309
- write: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8"),
310
- read: () => resolveConfig(configModule)
311
- }
311
+ configurationFile: configModule,
312
+ onUpdate: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8")
312
313
  });
313
314
  }
314
315
  }
@@ -321,7 +322,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
321
322
  const uncoveredFiles = includedFiles.map((file) => pathToFileURL(resolve(this.ctx.config.root, file))).filter((file) => !testedFiles.includes(file.pathname));
322
323
  let merged = { result: [] };
323
324
  let index = 0;
324
- for (const chunk of toSlices(uncoveredFiles, this.options.processingConcurrency)) {
325
+ for (const chunk of this.toSlices(uncoveredFiles, this.options.processingConcurrency)) {
325
326
  if (debug.enabled) {
326
327
  index += chunk.length;
327
328
  debug("Uncovered files %d/%d", index, uncoveredFiles.length);
@@ -364,7 +365,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
364
365
  originalSource: sourcesContent,
365
366
  source: code || sourcesContent,
366
367
  sourceMap: {
367
- sourcemap: removeViteHelpersFromSourceMaps(code, {
368
+ sourcemap: excludeGeneratedCode(code, {
368
369
  ...map,
369
370
  version: 3,
370
371
  sources: [url],
@@ -380,7 +381,7 @@ class V8CoverageProvider extends BaseCoverageProvider {
380
381
  const scriptCoverages = coverage.result.filter((result) => this.testExclude.shouldInstrument(fileURLToPath(result.url)));
381
382
  const coverageMap = libCoverage.createCoverageMap({});
382
383
  let index = 0;
383
- for (const chunk of toSlices(scriptCoverages, this.options.processingConcurrency)) {
384
+ for (const chunk of this.toSlices(scriptCoverages, this.options.processingConcurrency)) {
384
385
  if (debug.enabled) {
385
386
  index += chunk.length;
386
387
  debug("Converting %d/%d", index, scriptCoverages.length);
@@ -401,16 +402,17 @@ async function transformCoverage(coverageMap) {
401
402
  const sourceMapStore = libSourceMaps.createSourceMapStore();
402
403
  return await sourceMapStore.transformCoverage(coverageMap);
403
404
  }
404
- function removeViteHelpersFromSourceMaps(source, map) {
405
- if (!source || !source.match(VITE_EXPORTS_LINE_PATTERN))
405
+ function excludeGeneratedCode(source, map) {
406
+ if (!source)
407
+ return map;
408
+ if (!source.match(VITE_EXPORTS_LINE_PATTERN) && !source.match(DECORATOR_METADATA_PATTERN))
406
409
  return map;
407
- const sourceWithoutHelpers = new MagicString(source);
408
- sourceWithoutHelpers.replaceAll(VITE_EXPORTS_LINE_PATTERN, "\n");
409
- const mapWithoutHelpers = sourceWithoutHelpers.generateMap({
410
- hires: "boundary"
411
- });
410
+ const trimmed = new MagicString(source);
411
+ trimmed.replaceAll(VITE_EXPORTS_LINE_PATTERN, "\n");
412
+ trimmed.replaceAll(DECORATOR_METADATA_PATTERN, (match) => "\n".repeat(match.split("\n").length - 1));
413
+ const trimmedMap = trimmed.generateMap({ hires: "boundary" });
412
414
  const combinedMap = remapping(
413
- [{ ...mapWithoutHelpers, version: 3 }, map],
415
+ [{ ...trimmedMap, version: 3 }, map],
414
416
  () => null
415
417
  );
416
418
  return combinedMap;
@@ -430,36 +432,5 @@ function normalizeTransformResults(fetchCache) {
430
432
  }
431
433
  return normalized;
432
434
  }
433
- function hasTerminalReporter(reporters) {
434
- return reporters.some(([reporter]) => reporter === "text" || reporter === "text-summary" || reporter === "text-lcov" || reporter === "teamcity");
435
- }
436
- function toSlices(array, size) {
437
- return array.reduce((chunks, item) => {
438
- const index = Math.max(0, chunks.length - 1);
439
- const lastChunk = chunks[index] || [];
440
- chunks[index] = lastChunk;
441
- if (lastChunk.length >= size)
442
- chunks.push([item]);
443
- else
444
- lastChunk.push(item);
445
- return chunks;
446
- }, []);
447
- }
448
- function resolveConfig(configModule) {
449
- const mod = configModule.exports.default;
450
- try {
451
- if (mod.$type === "object")
452
- return mod;
453
- if (mod.$type === "function-call") {
454
- if (mod.$args[0].$type === "object")
455
- return mod.$args[0];
456
- if (mod.$args[0].$type === "arrow-function-expression" && mod.$args[0].$body.$type === "object")
457
- return mod.$args[0].$body;
458
- }
459
- } catch (error) {
460
- throw new Error(error instanceof Error ? error.message : String(error));
461
- }
462
- throw new Error("Failed to update coverage thresholds. Configuration file is too complex.");
463
- }
464
435
 
465
436
  export { V8CoverageProvider };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/coverage-v8",
3
3
  "type": "module",
4
- "version": "1.2.2",
4
+ "version": "1.3.1",
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.0.0"
40
+ "vitest": "1.3.1"
41
41
  },
42
42
  "dependencies": {
43
43
  "@ampproject/remapping": "^2.2.1",
@@ -61,8 +61,8 @@
61
61
  "@types/istanbul-lib-source-maps": "^4.0.4",
62
62
  "@types/istanbul-reports": "^3.0.4",
63
63
  "pathe": "^1.1.1",
64
- "vite-node": "1.2.2",
65
- "vitest": "1.2.2"
64
+ "vite-node": "1.3.1",
65
+ "vitest": "1.3.1"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "rimraf dist && rollup -c",