@vitest/coverage-istanbul 1.0.0-beta.4 → 1.0.0-beta.6
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
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-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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,52 +217,40 @@ class IstanbulCoverageProvider extends BaseCoverageProvider {
|
|
213
217
|
...reporter[1]
|
214
218
|
}).execute(context);
|
215
219
|
}
|
216
|
-
if (this.options.
|
217
|
-
this.
|
220
|
+
if (this.options.thresholds) {
|
221
|
+
const resolvedThresholds = this.resolveThresholds({
|
218
222
|
coverageMap,
|
219
|
-
thresholds:
|
220
|
-
|
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
|
-
|
229
|
-
|
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) {
|
243
247
|
const includedFiles = await this.testExclude.glob(this.ctx.config.root);
|
244
248
|
const uncoveredFiles = includedFiles.map((file) => resolve(this.ctx.config.root, file)).filter((file) => !coveredFiles.includes(file));
|
245
|
-
const transformResults = await Promise.all(uncoveredFiles.map(async (filename) => {
|
246
|
-
const transformResult = await this.ctx.vitenode.transformRequest(filename);
|
247
|
-
return { transformResult, filename };
|
248
|
-
}));
|
249
249
|
const coverageMap = libCoverage.createCoverageMap({});
|
250
|
-
for (const
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
transformResult.code,
|
255
|
-
filename,
|
256
|
-
sourceMap
|
257
|
-
);
|
258
|
-
const lastCoverage = this.instrumenter.lastFileCoverage();
|
259
|
-
if (lastCoverage)
|
260
|
-
coverageMap.addFileCoverage(lastCoverage);
|
261
|
-
}
|
250
|
+
for (const filename of uncoveredFiles) {
|
251
|
+
await this.ctx.vitenode.transformRequest(filename);
|
252
|
+
const lastCoverage = this.instrumenter.lastFileCoverage();
|
253
|
+
coverageMap.addFileCoverage(lastCoverage);
|
262
254
|
}
|
263
255
|
return coverageMap.data;
|
264
256
|
}
|
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.
|
4
|
+
"version": "1.0.0-beta.6",
|
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
|
-
"
|
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.
|
44
|
-
"istanbul-lib-instrument": "^6.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.
|
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.
|
53
|
-
"@types/istanbul-lib-instrument": "^1.7.
|
54
|
-
"@types/istanbul-lib-report": "^3.0.
|
55
|
-
"@types/istanbul-lib-source-maps": "^4.0.
|
56
|
-
"@types/istanbul-reports": "^3.0.
|
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.
|
59
|
+
"vitest": "1.0.0-beta.6"
|
59
60
|
},
|
60
61
|
"scripts": {
|
61
62
|
"build": "rimraf dist && rollup -c",
|
File without changes
|