@vitest/coverage-istanbul 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
@@ -16,8 +16,8 @@ interface TestExclude {
16
16
  excludeNodeModules?: boolean;
17
17
  relativePath?: boolean;
18
18
  }): {
19
- shouldInstrument(filePath: string): boolean;
20
- glob(cwd: string): Promise<string[]>;
19
+ shouldInstrument: (filePath: string) => boolean;
20
+ glob: (cwd: string) => Promise<string[]>;
21
21
  };
22
22
  }
23
23
  declare const DEFAULT_PROJECT: unique symbol;
package/dist/provider.js CHANGED
@@ -156,7 +156,9 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
156
156
  extension: this.options.extension,
157
157
  relativePath: !this.options.allowExternal
158
158
  });
159
- this.coverageFilesDirectory = resolve(this.options.reportsDirectory, ".tmp");
159
+ const shard = this.ctx.config.shard;
160
+ const tempDirectory = `.tmp${shard ? `-${shard.index}-${shard.count}` : ""}`;
161
+ this.coverageFilesDirectory = resolve(this.options.reportsDirectory, tempDirectory);
160
162
  }
161
163
  resolveOptions() {
162
164
  return this.options;
@@ -166,6 +168,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
166
168
  return;
167
169
  const sourceMap = pluginCtx.getCombinedSourcemap();
168
170
  sourceMap.sources = sourceMap.sources.map(removeQueryParameters);
171
+ sourceCode = sourceCode.replaceAll("_ts_decorate", "/* istanbul ignore next */_ts_decorate");
169
172
  const code = this.instrumenter.instrumentSync(sourceCode, id, sourceMap);
170
173
  const map = this.instrumenter.lastSourceMap();
171
174
  return { code, map };
@@ -208,7 +211,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
208
211
  for (const coveragePerProject of this.coverageFiles.values()) {
209
212
  for (const filenames of [coveragePerProject.ssr, coveragePerProject.web]) {
210
213
  const coverageMapByTransformMode = libCoverage.createCoverageMap({});
211
- for (const chunk of toSlices(filenames, this.options.processingConcurrency)) {
214
+ for (const chunk of this.toSlices(filenames, this.options.processingConcurrency)) {
212
215
  if (debug.enabled) {
213
216
  index += chunk.length;
214
217
  debug("Covered files %d/%d", index, total);
@@ -233,7 +236,7 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
233
236
  coverageMap,
234
237
  watermarks: this.options.watermarks
235
238
  });
236
- if (hasTerminalReporter(this.options.reporter))
239
+ if (this.hasTerminalReporter(this.options.reporter))
237
240
  this.ctx.logger.log(c.blue(" % ") + c.dim("Coverage report from ") + c.yellow(this.name));
238
241
  for (const reporter of this.options.reporter) {
239
242
  reports.create(reporter[0], {
@@ -260,10 +263,8 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
260
263
  this.updateThresholds({
261
264
  thresholds: resolvedThresholds,
262
265
  perFile: this.options.thresholds.perFile,
263
- configurationFile: {
264
- write: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8"),
265
- read: () => resolveConfig(configModule)
266
- }
266
+ configurationFile: configModule,
267
+ onUpdate: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8")
267
268
  });
268
269
  }
269
270
  }
@@ -314,36 +315,5 @@ function includeImplicitElseBranches(coverageMap) {
314
315
  function isEmptyCoverageRange(range) {
315
316
  return range.start === void 0 || range.start.line === void 0 || range.start.column === void 0 || range.end === void 0 || range.end.line === void 0 || range.end.column === void 0;
316
317
  }
317
- function hasTerminalReporter(reporters) {
318
- return reporters.some(([reporter]) => reporter === "text" || reporter === "text-summary" || reporter === "text-lcov" || reporter === "teamcity");
319
- }
320
- function toSlices(array, size) {
321
- return array.reduce((chunks, item) => {
322
- const index = Math.max(0, chunks.length - 1);
323
- const lastChunk = chunks[index] || [];
324
- chunks[index] = lastChunk;
325
- if (lastChunk.length >= size)
326
- chunks.push([item]);
327
- else
328
- lastChunk.push(item);
329
- return chunks;
330
- }, []);
331
- }
332
- function resolveConfig(configModule) {
333
- const mod = configModule.exports.default;
334
- try {
335
- if (mod.$type === "object")
336
- return mod;
337
- if (mod.$type === "function-call") {
338
- if (mod.$args[0].$type === "object")
339
- return mod.$args[0];
340
- if (mod.$args[0].$type === "arrow-function-expression" && mod.$args[0].$body.$type === "object")
341
- return mod.$args[0].$body;
342
- }
343
- } catch (error) {
344
- throw new Error(error instanceof Error ? error.message : String(error));
345
- }
346
- throw new Error("Failed to update coverage thresholds. Configuration file is too complex.");
347
- }
348
318
 
349
319
  export { IstanbulCoverageProvider };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/coverage-istanbul",
3
3
  "type": "module",
4
- "version": "1.2.2",
4
+ "version": "1.3.1",
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": "^1.0.0"
40
+ "vitest": "1.3.1"
41
41
  },
42
42
  "dependencies": {
43
43
  "debug": "^4.3.4",
@@ -58,7 +58,7 @@
58
58
  "@types/istanbul-lib-source-maps": "^4.0.4",
59
59
  "@types/istanbul-reports": "^3.0.4",
60
60
  "pathe": "^1.1.1",
61
- "vitest": "1.2.2"
61
+ "vitest": "1.3.1"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "rimraf dist && rollup -c",