@vitest/coverage-v8 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/provider.js +30 -26
- package/package.json +13 -12
package/dist/provider.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { existsSync, promises } from 'node:fs';
|
1
|
+
import { existsSync, promises, writeFileSync } from 'node:fs';
|
2
2
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
3
3
|
import v8ToIstanbul from 'v8-to-istanbul';
|
4
4
|
import { mergeProcessCovs } from '@bcoe/v8-coverage';
|
@@ -7,6 +7,7 @@ import reports from 'istanbul-reports';
|
|
7
7
|
import libCoverage from 'istanbul-lib-coverage';
|
8
8
|
import libSourceMaps from 'istanbul-lib-source-maps';
|
9
9
|
import MagicString from 'magic-string';
|
10
|
+
import { parseModule } from 'magicast';
|
10
11
|
import remapping from '@ampproject/remapping';
|
11
12
|
import c from 'picocolors';
|
12
13
|
import { provider } from 'std-env';
|
@@ -186,10 +187,13 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
186
187
|
provider: "v8",
|
187
188
|
reporter: this.resolveReporters(config.reporter || coverageConfigDefaults.reporter),
|
188
189
|
reportsDirectory: resolve(ctx.config.root, config.reportsDirectory || coverageConfigDefaults.reportsDirectory),
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
190
|
+
thresholds: config.thresholds && {
|
191
|
+
...config.thresholds,
|
192
|
+
lines: config.thresholds["100"] ? 100 : config.thresholds.lines,
|
193
|
+
branches: config.thresholds["100"] ? 100 : config.thresholds.branches,
|
194
|
+
functions: config.thresholds["100"] ? 100 : config.thresholds.functions,
|
195
|
+
statements: config.thresholds["100"] ? 100 : config.thresholds.statements
|
196
|
+
}
|
193
197
|
};
|
194
198
|
this.testExclude = new _TestExclude({
|
195
199
|
cwd: ctx.config.root,
|
@@ -253,30 +257,30 @@ class V8CoverageProvider extends BaseCoverageProvider {
|
|
253
257
|
...reporter[1]
|
254
258
|
}).execute(context);
|
255
259
|
}
|
256
|
-
if (this.options.
|
257
|
-
this.
|
260
|
+
if (this.options.thresholds) {
|
261
|
+
const resolvedThresholds = this.resolveThresholds({
|
258
262
|
coverageMap,
|
259
|
-
thresholds:
|
260
|
-
|
261
|
-
functions: this.options.functions,
|
262
|
-
lines: this.options.lines,
|
263
|
-
statements: this.options.statements
|
264
|
-
},
|
265
|
-
perFile: this.options.perFile
|
263
|
+
thresholds: this.options.thresholds,
|
264
|
+
createCoverageMap: () => libCoverage.createCoverageMap({})
|
266
265
|
});
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
coverageMap,
|
271
|
-
thresholds: {
|
272
|
-
branches: this.options.branches,
|
273
|
-
functions: this.options.functions,
|
274
|
-
lines: this.options.lines,
|
275
|
-
statements: this.options.statements
|
276
|
-
},
|
277
|
-
perFile: this.options.perFile,
|
278
|
-
configurationFile: this.ctx.server.config.configFile
|
266
|
+
this.checkThresholds({
|
267
|
+
thresholds: resolvedThresholds,
|
268
|
+
perFile: this.options.thresholds.perFile
|
279
269
|
});
|
270
|
+
if (this.options.thresholds.autoUpdate && allTestsRun) {
|
271
|
+
if (!this.ctx.server.config.configFile)
|
272
|
+
throw new Error('Missing configurationFile. The "coverage.thresholds.autoUpdate" can only be enabled when configuration file is used.');
|
273
|
+
const configFilePath = this.ctx.server.config.configFile;
|
274
|
+
const configModule = parseModule(await promises.readFile(configFilePath, "utf8"));
|
275
|
+
this.updateThresholds({
|
276
|
+
thresholds: resolvedThresholds,
|
277
|
+
perFile: this.options.thresholds.perFile,
|
278
|
+
configurationFile: {
|
279
|
+
write: () => writeFileSync(configFilePath, configModule.generate().code, "utf-8"),
|
280
|
+
read: () => configModule.exports.default.$type === "function-call" ? configModule.exports.default.$args[0] : configModule.exports.default
|
281
|
+
}
|
282
|
+
});
|
283
|
+
}
|
280
284
|
}
|
281
285
|
}
|
282
286
|
async getUntestedFiles(testedFiles) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/coverage-v8",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.0-beta.
|
4
|
+
"version": "1.0.0-beta.6",
|
5
5
|
"description": "V8 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
|
},
|
@@ -42,24 +42,25 @@
|
|
42
42
|
"dependencies": {
|
43
43
|
"@ampproject/remapping": "^2.2.1",
|
44
44
|
"@bcoe/v8-coverage": "^0.2.3",
|
45
|
-
"istanbul-lib-coverage": "^3.2.
|
45
|
+
"istanbul-lib-coverage": "^3.2.2",
|
46
46
|
"istanbul-lib-report": "^3.0.1",
|
47
47
|
"istanbul-lib-source-maps": "^4.0.1",
|
48
|
-
"istanbul-reports": "^3.1.
|
48
|
+
"istanbul-reports": "^3.1.6",
|
49
49
|
"magic-string": "^0.30.5",
|
50
|
+
"magicast": "^0.3.2",
|
50
51
|
"picocolors": "^1.0.0",
|
51
|
-
"std-env": "^3.
|
52
|
+
"std-env": "^3.5.0",
|
52
53
|
"test-exclude": "^6.0.0",
|
53
|
-
"v8-to-istanbul": "^9.
|
54
|
+
"v8-to-istanbul": "^9.2.0"
|
54
55
|
},
|
55
56
|
"devDependencies": {
|
56
|
-
"@types/istanbul-lib-coverage": "^2.0.
|
57
|
-
"@types/istanbul-lib-report": "^3.0.
|
58
|
-
"@types/istanbul-lib-source-maps": "^4.0.
|
59
|
-
"@types/istanbul-reports": "^3.0.
|
57
|
+
"@types/istanbul-lib-coverage": "^2.0.6",
|
58
|
+
"@types/istanbul-lib-report": "^3.0.3",
|
59
|
+
"@types/istanbul-lib-source-maps": "^4.0.4",
|
60
|
+
"@types/istanbul-reports": "^3.0.4",
|
60
61
|
"pathe": "^1.1.1",
|
61
|
-
"
|
62
|
-
"
|
62
|
+
"vitest": "1.0.0-beta.6",
|
63
|
+
"vite-node": "1.0.0-beta.6"
|
63
64
|
},
|
64
65
|
"scripts": {
|
65
66
|
"build": "rimraf dist && rollup -c",
|