@vitest/coverage-istanbul 1.0.0-beta.3 → 1.0.0-beta.5

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as COVERAGE_STORE_KEY } from './constants-758a8358.js';
1
+ import { C as COVERAGE_STORE_KEY } from './constants-DBqnqzn-.js';
2
2
 
3
3
  async function getProvider() {
4
4
  const providerPath = "./provider.js";
package/dist/provider.js CHANGED
@@ -1,14 +1,15 @@
1
- import { existsSync, promises } from 'node:fs';
1
+ import { existsSync, promises, writeFileSync } from 'node:fs';
2
2
  import { coverageConfigDefaults, defaultExclude, defaultInclude } from 'vitest/config';
3
3
  import { BaseCoverageProvider } from 'vitest/coverage';
4
4
  import c from 'picocolors';
5
+ import { parseModule } from 'magicast';
5
6
  import libReport from 'istanbul-lib-report';
6
7
  import reports from 'istanbul-reports';
7
8
  import libCoverage from 'istanbul-lib-coverage';
8
9
  import libSourceMaps from 'istanbul-lib-source-maps';
9
10
  import { createInstrumenter } from 'istanbul-lib-instrument';
10
11
  import _TestExclude from 'test-exclude';
11
- import { C as COVERAGE_STORE_KEY } from './constants-758a8358.js';
12
+ import { C as COVERAGE_STORE_KEY } from './constants-DBqnqzn-.js';
12
13
 
13
14
  function normalizeWindowsPath(input = "") {
14
15
  if (!input || !input.includes("\\")) {
@@ -129,10 +130,13 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
129
130
  provider: "istanbul",
130
131
  reportsDirectory: resolve(ctx.config.root, config.reportsDirectory || coverageConfigDefaults.reportsDirectory),
131
132
  reporter: this.resolveReporters(config.reporter || coverageConfigDefaults.reporter),
132
- lines: config["100"] ? 100 : config.lines,
133
- functions: config["100"] ? 100 : config.functions,
134
- branches: config["100"] ? 100 : config.branches,
135
- statements: config["100"] ? 100 : config.statements
133
+ thresholds: config.thresholds && {
134
+ ...config.thresholds,
135
+ lines: config.thresholds["100"] ? 100 : config.thresholds.lines,
136
+ branches: config.thresholds["100"] ? 100 : config.thresholds.branches,
137
+ functions: config.thresholds["100"] ? 100 : config.thresholds.functions,
138
+ statements: config.thresholds["100"] ? 100 : config.thresholds.statements
139
+ }
136
140
  };
137
141
  this.instrumenter = createInstrumenter({
138
142
  produceSourceMap: true,
@@ -213,30 +217,30 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
213
217
  ...reporter[1]
214
218
  }).execute(context);
215
219
  }
216
- if (this.options.branches || this.options.functions || this.options.lines || this.options.statements) {
217
- this.checkThresholds({
220
+ if (this.options.thresholds) {
221
+ const resolvedThresholds = this.resolveThresholds({
218
222
  coverageMap,
219
- thresholds: {
220
- branches: this.options.branches,
221
- functions: this.options.functions,
222
- lines: this.options.lines,
223
- statements: this.options.statements
224
- },
225
- perFile: this.options.perFile
223
+ thresholds: this.options.thresholds,
224
+ createCoverageMap: () => libCoverage.createCoverageMap({})
226
225
  });
227
- }
228
- if (this.options.thresholdAutoUpdate && allTestsRun) {
229
- this.updateThresholds({
230
- coverageMap,
231
- thresholds: {
232
- branches: this.options.branches,
233
- functions: this.options.functions,
234
- lines: this.options.lines,
235
- statements: this.options.statements
236
- },
237
- perFile: this.options.perFile,
238
- configurationFile: this.ctx.server.config.configFile
226
+ this.checkThresholds({
227
+ thresholds: resolvedThresholds,
228
+ perFile: this.options.thresholds.perFile
239
229
  });
230
+ if (this.options.thresholds.autoUpdate && allTestsRun) {
231
+ if (!this.ctx.server.config.configFile)
232
+ throw new Error('Missing configurationFile. The "coverage.thresholds.autoUpdate" can only be enabled when configuration file is used.');
233
+ const configFilePath = this.ctx.server.config.configFile;
234
+ const configModule = parseModule(await promises.readFile(configFilePath, "utf8"));
235
+ this.updateThresholds({
236
+ thresholds: resolvedThresholds,
237
+ perFile: this.options.thresholds.perFile,
238
+ configurationFile: {
239
+ write: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8"),
240
+ read: () => configModule.exports.default.$type === "function-call" ? configModule.exports.default.$args[0] : configModule.exports.default
241
+ }
242
+ });
243
+ }
240
244
  }
241
245
  }
242
246
  async getCoverageMapForUncoveredFiles(coveredFiles) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/coverage-istanbul",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.3",
4
+ "version": "1.0.0-beta.5",
5
5
  "description": "Istanbul coverage provider for Vitest",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "exports": {
27
27
  ".": {
28
28
  "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js"
29
+ "default": "./dist/index.js"
30
30
  },
31
31
  "./*": "./*"
32
32
  },
@@ -40,22 +40,23 @@
40
40
  "vitest": "^1.0.0-0"
41
41
  },
42
42
  "dependencies": {
43
- "istanbul-lib-coverage": "^3.2.0",
44
- "istanbul-lib-instrument": "^6.0.0",
43
+ "istanbul-lib-coverage": "^3.2.2",
44
+ "istanbul-lib-instrument": "^6.0.1",
45
45
  "istanbul-lib-report": "^3.0.1",
46
46
  "istanbul-lib-source-maps": "^4.0.1",
47
- "istanbul-reports": "^3.1.5",
47
+ "istanbul-reports": "^3.1.6",
48
+ "magicast": "^0.3.2",
48
49
  "picocolors": "^1.0.0",
49
50
  "test-exclude": "^6.0.0"
50
51
  },
51
52
  "devDependencies": {
52
- "@types/istanbul-lib-coverage": "^2.0.4",
53
- "@types/istanbul-lib-instrument": "^1.7.4",
54
- "@types/istanbul-lib-report": "^3.0.0",
55
- "@types/istanbul-lib-source-maps": "^4.0.1",
56
- "@types/istanbul-reports": "^3.0.1",
53
+ "@types/istanbul-lib-coverage": "^2.0.6",
54
+ "@types/istanbul-lib-instrument": "^1.7.7",
55
+ "@types/istanbul-lib-report": "^3.0.3",
56
+ "@types/istanbul-lib-source-maps": "^4.0.4",
57
+ "@types/istanbul-reports": "^3.0.4",
57
58
  "pathe": "^1.1.1",
58
- "vitest": "1.0.0-beta.3"
59
+ "vitest": "1.0.0-beta.5"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "rimraf dist && rollup -c",