@flakiness/vitest 1.1.0 → 1.2.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/README.md +2 -0
- package/lib/reporter.js +15 -18
- package/package.json +4 -4
- package/types/src/reporter.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://flakiness.io/flakiness/vitest)
|
|
2
|
+
|
|
1
3
|
# Flakiness.io Vitest Reporter
|
|
2
4
|
|
|
3
5
|
A custom Vitest reporter that generates Flakiness Reports from your Vitest test runs. The reporter automatically converts Vitest test results into the standardized [Flakiness JSON format](https://github.com/flakiness/flakiness-report), capturing test outcomes, system utilization, and environment information.
|
package/lib/reporter.js
CHANGED
|
@@ -26,7 +26,7 @@ class FKVitestReporter {
|
|
|
26
26
|
}
|
|
27
27
|
onTestRunStart() {
|
|
28
28
|
assert(this._vitest, "onInit must be called before onTestRunStart");
|
|
29
|
-
this._impl = ReporterImpl.create(this._vitest.config.root, this._options, this._logger, this._vitest.config.config);
|
|
29
|
+
this._impl = ReporterImpl.create(this._vitest.config.root, this._vitest.projects, this._options, this._logger, this._vitest.config.config);
|
|
30
30
|
}
|
|
31
31
|
async onTestRunEnd(testModules, unhandledErrors, reason) {
|
|
32
32
|
await this._impl?.onTestRunEnd(testModules, unhandledErrors, reason);
|
|
@@ -35,12 +35,15 @@ class FKVitestReporter {
|
|
|
35
35
|
}
|
|
36
36
|
const gTestToTestCaseId = /* @__PURE__ */ new WeakMap();
|
|
37
37
|
class ReporterImpl {
|
|
38
|
-
constructor(_worktree, _commitId, _options, _logger, _configPath) {
|
|
38
|
+
constructor(_worktree, projects, _commitId, _options, _logger, _configPath) {
|
|
39
39
|
this._worktree = _worktree;
|
|
40
40
|
this._commitId = _commitId;
|
|
41
41
|
this._options = _options;
|
|
42
42
|
this._logger = _logger;
|
|
43
43
|
this._configPath = _configPath;
|
|
44
|
+
this._environments = projects.map((project) => ReportUtils.createEnvironment({
|
|
45
|
+
name: this._envName(project)
|
|
46
|
+
}));
|
|
44
47
|
this._sampleSystem = this._sampleSystem.bind(this);
|
|
45
48
|
this._sampleSystem();
|
|
46
49
|
}
|
|
@@ -49,16 +52,14 @@ class ReporterImpl {
|
|
|
49
52
|
_ramUtilization = new RAMUtilization({ precision: 10 });
|
|
50
53
|
_startTimestamp = Date.now();
|
|
51
54
|
_stdio = /* @__PURE__ */ new Map();
|
|
52
|
-
// In Vitest, all projects MUST HAVE UNIQUE NAMES.
|
|
53
|
-
// So we create environments per project name.
|
|
54
55
|
_environments = [];
|
|
55
|
-
static create(rootPath, options, logger, config) {
|
|
56
|
+
static create(rootPath, projects, options, logger, config) {
|
|
56
57
|
let commitId;
|
|
57
58
|
let worktree;
|
|
58
59
|
try {
|
|
59
60
|
worktree = GitWorktree.create(rootPath);
|
|
60
61
|
commitId = worktree.headCommitId();
|
|
61
|
-
return new ReporterImpl(worktree, commitId, options, logger, config);
|
|
62
|
+
return new ReporterImpl(worktree, projects, commitId, options, logger, config);
|
|
62
63
|
} catch (e) {
|
|
63
64
|
logger.warn(`[flakiness.io] Failed to fetch commit info - is this a git repo?`);
|
|
64
65
|
logger.error(`[flakiness.io] Report is NOT generated.`);
|
|
@@ -80,16 +81,8 @@ class ReporterImpl {
|
|
|
80
81
|
}
|
|
81
82
|
entries.push(log);
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
let idx = this._environments.findIndex((env) => env.name === projectName);
|
|
86
|
-
if (idx === -1) {
|
|
87
|
-
idx = this._environments.length;
|
|
88
|
-
this._environments.push(ReportUtils.createEnvironment({
|
|
89
|
-
name: projectName
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
return idx;
|
|
84
|
+
_envName(project) {
|
|
85
|
+
return project.name || "vitest";
|
|
93
86
|
}
|
|
94
87
|
_errorLocation(stacks, testFile) {
|
|
95
88
|
const frame = stacks?.find((frame2) => this._worktree.gitPath(frame2.file) === testFile) ?? stacks?.find((frame2) => !frame2.file.includes("node_modules"));
|
|
@@ -117,7 +110,8 @@ class ReporterImpl {
|
|
|
117
110
|
this._collectTest(fkSuite, t);
|
|
118
111
|
}
|
|
119
112
|
async _collectTest(fkParent, testCase) {
|
|
120
|
-
const environmentIdx = this.
|
|
113
|
+
const environmentIdx = this._environments.findIndex((env) => env.name === this._envName(testCase.project));
|
|
114
|
+
assert(environmentIdx !== -1, `Failed to find environment for test ${testCase.fullName}`);
|
|
121
115
|
const fkTest = {
|
|
122
116
|
attempts: [],
|
|
123
117
|
title: testCase.name,
|
|
@@ -336,7 +330,10 @@ class ReporterImpl {
|
|
|
336
330
|
startTimestamp: this._startTimestamp,
|
|
337
331
|
duration,
|
|
338
332
|
suites: fileSuites,
|
|
339
|
-
unattributedErrors:
|
|
333
|
+
unattributedErrors: [
|
|
334
|
+
unhandledErrors,
|
|
335
|
+
testModules.map((t) => t.errors()).flat()
|
|
336
|
+
].flat().map((error) => ({
|
|
340
337
|
message: error.message,
|
|
341
338
|
stack: error.stack,
|
|
342
339
|
location: this._errorLocation(error.stacks)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flakiness/vitest",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/reporter.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@flakiness/vitest": "
|
|
15
|
+
"@flakiness/vitest": "1.2.0",
|
|
16
16
|
"@types/node": "^25.3.3",
|
|
17
17
|
"@vitest/utils": "^4.0.18",
|
|
18
18
|
"esbuild": "^0.27.3",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"vitest": "^4.0.18"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@flakiness/flakiness-report": "^0.
|
|
26
|
-
"@flakiness/sdk": "^2.2.
|
|
25
|
+
"@flakiness/flakiness-report": "^0.28.0",
|
|
26
|
+
"@flakiness/sdk": "^2.2.2",
|
|
27
27
|
"chalk": "^5.6.2"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../../src/reporter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAY,UAAU,
|
|
1
|
+
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../../src/reporter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAY,UAAU,EAAe,gBAAgB,EAAa,MAAM,EAAE,MAAM,aAAa,CAAC;AAC3H,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAC,QAAQ,CAAC;CAC9B,CAAA;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,OAAO,gBAAiB,YAAW,QAAQ;IAS3C,OAAO,CAAC,QAAQ;IAR5B,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,OAAO,CAId;gBAEmB,QAAQ,EAAE,uBAAuB;IAGrD,gBAAgB,CAAC,MAAM,EAAE,cAAc;IAIjC,gBAAgB,CAAC,GAAG,EAAE,cAAc;IAI1C,MAAM,CAAC,MAAM,EAAE,MAAM;IAIrB,cAAc;IAOR,YAAY,CAAC,WAAW,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,eAAe,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,gBAAgB;CAIrI"}
|