@qanalyzer/forge-vitest 1.1.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 +202 -0
- package/README.md +72 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +126 -0
- package/dist/report-builder.d.ts +24 -0
- package/dist/report-builder.js +80 -0
- package/dist/vitest.d.ts +38 -0
- package/dist/vitest.js +104 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright © 2026 JSoft
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @qanalyzer/forge-vitest
|
|
2
|
+
|
|
3
|
+
Vitest reporter for **QAnalyzer** (Jira Forge quality hub).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @qanalyzer/forge-vitest @qanalyzer/forge-commons
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configure
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vitest.config.ts
|
|
15
|
+
import { defineConfig } from 'vitest/config';
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
test: {
|
|
19
|
+
reporters: [
|
|
20
|
+
'default',
|
|
21
|
+
[
|
|
22
|
+
'@qanalyzer/forge-vitest',
|
|
23
|
+
{
|
|
24
|
+
// Defaults to mode=off (no credentials required)
|
|
25
|
+
// mode: 'ingest' | 'file' | 'off',
|
|
26
|
+
// projectKey: 'DEMO',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Modes
|
|
35
|
+
|
|
36
|
+
| Mode | Behavior |
|
|
37
|
+
| ---- | -------- |
|
|
38
|
+
| `off` (default) | No network / file write |
|
|
39
|
+
| `file` | Writes ingest payload (default `./qanalyzer-results.json`) |
|
|
40
|
+
| `ingest` | POSTs the payload with `format: vitest-json` |
|
|
41
|
+
|
|
42
|
+
Env (same as CLI): `QANALYZER_MODE`, `QANALYZER_PROJECT_KEY`, `QANALYZER_INGEST_URL`, `QANALYZER_INGEST_TOKEN`, `QANALYZER_LAUNCH_NAME`.
|
|
43
|
+
|
|
44
|
+
## Helpers
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { describe, expect, test } from 'vitest';
|
|
48
|
+
import { withQa } from '@qanalyzer/forge-vitest/vitest';
|
|
49
|
+
|
|
50
|
+
test(
|
|
51
|
+
'AUTH-101 login',
|
|
52
|
+
withQa(async ({ qa }) => {
|
|
53
|
+
await qa.suite('Auth');
|
|
54
|
+
await qa.step('open form', async () => {
|
|
55
|
+
expect(true).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Prefer **Jira issue keys in test titles**. Put competitive/reference notes in internal docs only — not in this package.
|
|
62
|
+
|
|
63
|
+
`withQa` / `qa.*` annotations are collected by the reporter into `assertionResults[].meta.qa` (suite, fields, steps, comments) on Path B ingest/file.
|
|
64
|
+
|
|
65
|
+
## Dual path
|
|
66
|
+
|
|
67
|
+
You can still use native JSON + CLI:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx vitest run --reporter=json --outputFile=qanalyzer-results.json
|
|
71
|
+
npx @qanalyzer/forge-api-client --project DEMO --report qanalyzer-results.json
|
|
72
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Reporter } from 'vitest/reporters';
|
|
2
|
+
import type { TestCase } from 'vitest/node';
|
|
3
|
+
import { type OptionsType } from '@qanalyzer/forge-commons';
|
|
4
|
+
export type VitestQaOptions = OptionsType;
|
|
5
|
+
/**
|
|
6
|
+
* Vitest custom reporter for QAnalyzer.
|
|
7
|
+
* Configure: `reporters: ['default', '@qanalyzer/forge-vitest']` or `['@qanalyzer/forge-vitest', { mode: 'ingest', ... }]`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class VitestQaReporter implements Reporter {
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly cases;
|
|
12
|
+
private readonly startedAt;
|
|
13
|
+
private publishPromise;
|
|
14
|
+
constructor(options?: VitestQaOptions);
|
|
15
|
+
onTestCaseResult(testCase: TestCase): void;
|
|
16
|
+
onTestRunEnd(): Promise<void>;
|
|
17
|
+
private publish;
|
|
18
|
+
}
|
|
19
|
+
export default VitestQaReporter;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VitestQaReporter = void 0;
|
|
4
|
+
const forge_commons_1 = require("@qanalyzer/forge-commons");
|
|
5
|
+
const report_builder_1 = require("./report-builder");
|
|
6
|
+
function mapState(state) {
|
|
7
|
+
switch ((state ?? '').toLowerCase()) {
|
|
8
|
+
case 'pass':
|
|
9
|
+
case 'passed':
|
|
10
|
+
return 'passed';
|
|
11
|
+
case 'fail':
|
|
12
|
+
case 'failed':
|
|
13
|
+
return 'failed';
|
|
14
|
+
case 'skip':
|
|
15
|
+
case 'skipped':
|
|
16
|
+
return 'skipped';
|
|
17
|
+
case 'todo':
|
|
18
|
+
return 'todo';
|
|
19
|
+
case 'pending':
|
|
20
|
+
return 'pending';
|
|
21
|
+
default:
|
|
22
|
+
return 'failed';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function collectFromTestCase(testCase) {
|
|
26
|
+
const result = testCase.result();
|
|
27
|
+
const diagnostic = typeof testCase.diagnostic === 'function' ? testCase.diagnostic() : null;
|
|
28
|
+
const errors = result?.errors ?? [];
|
|
29
|
+
const failureMessages = errors.map((err) => {
|
|
30
|
+
if (!err)
|
|
31
|
+
return 'Test failed';
|
|
32
|
+
return err.stack ?? err.message ?? String(err);
|
|
33
|
+
});
|
|
34
|
+
const anyCase = testCase;
|
|
35
|
+
const moduleId = anyCase.moduleId ?? anyCase.file?.moduleId ?? 'unknown';
|
|
36
|
+
const ancestorTitles = [];
|
|
37
|
+
try {
|
|
38
|
+
let current = anyCase.parent;
|
|
39
|
+
const names = [];
|
|
40
|
+
while (current?.name) {
|
|
41
|
+
names.unshift(current.name);
|
|
42
|
+
current = current.parent;
|
|
43
|
+
}
|
|
44
|
+
ancestorTitles.push(...names);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// ignore suite walk failures
|
|
48
|
+
}
|
|
49
|
+
const acc = (0, forge_commons_1.createQaMetaAccumulator)();
|
|
50
|
+
try {
|
|
51
|
+
const annotations = typeof testCase.annotations === 'function' ? testCase.annotations() : [];
|
|
52
|
+
(0, forge_commons_1.applyQaAnnotations)(acc, annotations.map((a) => ({
|
|
53
|
+
message: a.message,
|
|
54
|
+
type: a.type,
|
|
55
|
+
body: a.body,
|
|
56
|
+
})));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// ignore annotation parse failures
|
|
60
|
+
}
|
|
61
|
+
const metaQa = (0, forge_commons_1.toQaMetaWire)(acc, { framework: 'vitest' });
|
|
62
|
+
return {
|
|
63
|
+
id: testCase.id,
|
|
64
|
+
name: testCase.name,
|
|
65
|
+
fullName: testCase.fullName || testCase.name,
|
|
66
|
+
filePath: moduleId,
|
|
67
|
+
ancestorTitles,
|
|
68
|
+
status: mapState(result?.state),
|
|
69
|
+
durationMs: diagnostic && typeof diagnostic.duration === 'number'
|
|
70
|
+
? Math.round(diagnostic.duration)
|
|
71
|
+
: null,
|
|
72
|
+
failureMessages,
|
|
73
|
+
startTime: diagnostic?.startTime,
|
|
74
|
+
metaQa,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Vitest custom reporter for QAnalyzer.
|
|
79
|
+
* Configure: `reporters: ['default', '@qanalyzer/forge-vitest']` or `['@qanalyzer/forge-vitest', { mode: 'ingest', ... }]`.
|
|
80
|
+
*/
|
|
81
|
+
class VitestQaReporter {
|
|
82
|
+
options;
|
|
83
|
+
cases = [];
|
|
84
|
+
startedAt = Date.now();
|
|
85
|
+
publishPromise = null;
|
|
86
|
+
constructor(options = {}) {
|
|
87
|
+
this.options = options;
|
|
88
|
+
}
|
|
89
|
+
onTestCaseResult(testCase) {
|
|
90
|
+
try {
|
|
91
|
+
this.cases.push(collectFromTestCase(testCase));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Never fail the Vitest run because of reporter collection errors
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async onTestRunEnd() {
|
|
98
|
+
if (this.publishPromise) {
|
|
99
|
+
await this.publishPromise;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.publishPromise = this.publish();
|
|
103
|
+
await this.publishPromise;
|
|
104
|
+
}
|
|
105
|
+
async publish() {
|
|
106
|
+
forge_commons_1.QAnalyzerReporter.resetInstance();
|
|
107
|
+
const reporter = forge_commons_1.QAnalyzerReporter.getInstance({
|
|
108
|
+
...this.options,
|
|
109
|
+
mode: this.options.mode ?? forge_commons_1.ModeEnum.off,
|
|
110
|
+
});
|
|
111
|
+
const mode = reporter.getConfig().mode ?? forge_commons_1.ModeEnum.off;
|
|
112
|
+
if (mode === forge_commons_1.ModeEnum.off) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const report = (0, report_builder_1.buildJestCompatibleReport)((0, report_builder_1.groupCasesByFile)(this.cases), {
|
|
116
|
+
startTime: this.startedAt,
|
|
117
|
+
});
|
|
118
|
+
await reporter.publishReport(report, {
|
|
119
|
+
format: 'vitest-json',
|
|
120
|
+
launchName: this.options.launchName,
|
|
121
|
+
projectKey: this.options.projectKey,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.VitestQaReporter = VitestQaReporter;
|
|
126
|
+
exports.default = VitestQaReporter;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { JestVitestJsonReport, QaMetaWire } from '@qanalyzer/forge-commons';
|
|
2
|
+
/** Minimal case shape collected by the Vitest reporter (testable without Vitest runtime). */
|
|
3
|
+
export type CollectedCase = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
fullName: string;
|
|
7
|
+
filePath: string;
|
|
8
|
+
ancestorTitles: string[];
|
|
9
|
+
status: 'passed' | 'failed' | 'skipped' | 'pending' | 'todo';
|
|
10
|
+
durationMs: number | null;
|
|
11
|
+
failureMessages: string[];
|
|
12
|
+
startTime?: number;
|
|
13
|
+
/** FR41 assertionResults[].meta.qa */
|
|
14
|
+
metaQa?: QaMetaWire;
|
|
15
|
+
};
|
|
16
|
+
export type CollectedFile = {
|
|
17
|
+
filePath: string;
|
|
18
|
+
cases: CollectedCase[];
|
|
19
|
+
};
|
|
20
|
+
export declare function buildJestCompatibleReport(files: CollectedFile[], options?: {
|
|
21
|
+
startTime?: number;
|
|
22
|
+
}): JestVitestJsonReport;
|
|
23
|
+
/** Group flat cases by file path for report building. */
|
|
24
|
+
export declare function groupCasesByFile(cases: CollectedCase[]): CollectedFile[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildJestCompatibleReport = buildJestCompatibleReport;
|
|
4
|
+
exports.groupCasesByFile = groupCasesByFile;
|
|
5
|
+
function mapAssertionStatus(status) {
|
|
6
|
+
if (status === 'pending' || status === 'todo')
|
|
7
|
+
return 'pending';
|
|
8
|
+
return status;
|
|
9
|
+
}
|
|
10
|
+
function buildJestCompatibleReport(files, options = {}) {
|
|
11
|
+
const startTime = options.startTime ?? Date.now();
|
|
12
|
+
const testResults = [];
|
|
13
|
+
let numPassedTests = 0;
|
|
14
|
+
let numFailedTests = 0;
|
|
15
|
+
let numPendingTests = 0;
|
|
16
|
+
let numTodoTests = 0;
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const assertionResults = file.cases.map((c) => {
|
|
19
|
+
const status = mapAssertionStatus(c.status);
|
|
20
|
+
if (status === 'passed')
|
|
21
|
+
numPassedTests += 1;
|
|
22
|
+
else if (status === 'failed')
|
|
23
|
+
numFailedTests += 1;
|
|
24
|
+
else if (c.status === 'todo')
|
|
25
|
+
numTodoTests += 1;
|
|
26
|
+
else
|
|
27
|
+
numPendingTests += 1;
|
|
28
|
+
const assertion = {
|
|
29
|
+
ancestorTitles: c.ancestorTitles,
|
|
30
|
+
fullName: c.fullName,
|
|
31
|
+
title: c.name,
|
|
32
|
+
status,
|
|
33
|
+
duration: c.durationMs ?? undefined,
|
|
34
|
+
failureMessages: c.failureMessages,
|
|
35
|
+
};
|
|
36
|
+
if (c.metaQa) {
|
|
37
|
+
assertion.meta = { qa: c.metaQa };
|
|
38
|
+
}
|
|
39
|
+
return assertion;
|
|
40
|
+
});
|
|
41
|
+
const fileFailed = assertionResults.some((a) => a.status === 'failed');
|
|
42
|
+
testResults.push({
|
|
43
|
+
name: file.filePath,
|
|
44
|
+
status: fileFailed ? 'failed' : 'passed',
|
|
45
|
+
startTime,
|
|
46
|
+
endTime: Date.now(),
|
|
47
|
+
assertionResults,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const numTotalTests = numPassedTests + numFailedTests + numPendingTests + numTodoTests;
|
|
51
|
+
const numFailedTestSuites = testResults.filter((t) => t.status === 'failed').length;
|
|
52
|
+
const numPassedTestSuites = testResults.length - numFailedTestSuites;
|
|
53
|
+
return {
|
|
54
|
+
numTotalTestSuites: testResults.length,
|
|
55
|
+
numPassedTestSuites,
|
|
56
|
+
numFailedTestSuites,
|
|
57
|
+
numPendingTestSuites: 0,
|
|
58
|
+
numTotalTests,
|
|
59
|
+
numPassedTests,
|
|
60
|
+
numFailedTests,
|
|
61
|
+
numPendingTests,
|
|
62
|
+
numTodoTests,
|
|
63
|
+
startTime,
|
|
64
|
+
success: numFailedTests === 0,
|
|
65
|
+
testResults,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Group flat cases by file path for report building. */
|
|
69
|
+
function groupCasesByFile(cases) {
|
|
70
|
+
const map = new Map();
|
|
71
|
+
for (const c of cases) {
|
|
72
|
+
const list = map.get(c.filePath) ?? [];
|
|
73
|
+
list.push(c);
|
|
74
|
+
map.set(c.filePath, list);
|
|
75
|
+
}
|
|
76
|
+
return [...map.entries()].map(([filePath, fileCases]) => ({
|
|
77
|
+
filePath,
|
|
78
|
+
cases: fileCases,
|
|
79
|
+
}));
|
|
80
|
+
}
|
package/dist/vitest.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic helpers for Vitest tests (FR98 + Phase 3 FR107 attach upload).
|
|
3
|
+
*/
|
|
4
|
+
type StepFn = () => Promise<void> | void;
|
|
5
|
+
type AnnotateFn = (message: string, options?: {
|
|
6
|
+
type?: string;
|
|
7
|
+
body?: unknown;
|
|
8
|
+
}) => Promise<void>;
|
|
9
|
+
export type QaAttachInput = {
|
|
10
|
+
name?: string;
|
|
11
|
+
type?: string;
|
|
12
|
+
contentType?: string;
|
|
13
|
+
content?: string | Buffer | Uint8Array;
|
|
14
|
+
path?: string;
|
|
15
|
+
issueKey?: string;
|
|
16
|
+
};
|
|
17
|
+
export type QaHelpers = {
|
|
18
|
+
title(value: string): Promise<void>;
|
|
19
|
+
comment(value: string): Promise<void>;
|
|
20
|
+
suite(value: string): Promise<void>;
|
|
21
|
+
fields(values: Record<string, string>): Promise<void>;
|
|
22
|
+
parameters(values: Record<string, string>): Promise<void>;
|
|
23
|
+
ignore(): void;
|
|
24
|
+
step(name: string, body: StepFn): Promise<void>;
|
|
25
|
+
attach(attach: QaAttachInput): Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
export type QaTestContext = {
|
|
28
|
+
qa: QaHelpers;
|
|
29
|
+
annotate: AnnotateFn;
|
|
30
|
+
};
|
|
31
|
+
type VitestTestFn = (ctx: QaTestContext & Record<string, unknown>) => Promise<void> | void;
|
|
32
|
+
/**
|
|
33
|
+
* Wrap a Vitest test body to inject `qa` helpers (uses Vitest `annotate` when present).
|
|
34
|
+
*/
|
|
35
|
+
export declare function withQa(fn: VitestTestFn): VitestTestFn;
|
|
36
|
+
/** Standalone helpers when not using withQa (no-op annotate). */
|
|
37
|
+
export declare const qa: QaHelpers;
|
|
38
|
+
export {};
|
package/dist/vitest.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Programmatic helpers for Vitest tests (FR98 + Phase 3 FR107 attach upload).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.qa = void 0;
|
|
7
|
+
exports.withQa = withQa;
|
|
8
|
+
const forge_commons_1 = require("@qanalyzer/forge-commons");
|
|
9
|
+
function vitestCurrentTitle(ctx) {
|
|
10
|
+
const task = ctx?.task;
|
|
11
|
+
if (task?.fullName)
|
|
12
|
+
return task.fullName;
|
|
13
|
+
if (task?.name)
|
|
14
|
+
return task.name;
|
|
15
|
+
try {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
17
|
+
const { expect } = require('vitest');
|
|
18
|
+
return expect?.getState?.()?.currentTestName;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function createQaHelpers(annotate, titleSources) {
|
|
25
|
+
return {
|
|
26
|
+
async title(value) {
|
|
27
|
+
await annotate(`QA Title: ${value}`, { type: 'qa-title', body: value });
|
|
28
|
+
},
|
|
29
|
+
async comment(value) {
|
|
30
|
+
await annotate(`QA Comment: ${value}`, { type: 'qa-comment', body: value });
|
|
31
|
+
},
|
|
32
|
+
async suite(value) {
|
|
33
|
+
await annotate(`QA Suite: ${value}`, { type: 'qa-suite', body: value });
|
|
34
|
+
},
|
|
35
|
+
async fields(values) {
|
|
36
|
+
await annotate(`QA Fields: ${JSON.stringify(values)}`, {
|
|
37
|
+
type: 'qa-fields',
|
|
38
|
+
body: values,
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
async parameters(values) {
|
|
42
|
+
await annotate(`QA Parameters: ${JSON.stringify(values)}`, {
|
|
43
|
+
type: 'qa-parameters',
|
|
44
|
+
body: values,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
ignore() {
|
|
48
|
+
// Sync only
|
|
49
|
+
},
|
|
50
|
+
async step(name, body) {
|
|
51
|
+
await annotate(`QA Step: ${name}`, { type: 'qa-step', body: name });
|
|
52
|
+
try {
|
|
53
|
+
await body();
|
|
54
|
+
await annotate(`QA Step End: ${name}`, {
|
|
55
|
+
type: 'qa-step-end',
|
|
56
|
+
body: { name, status: 'passed' },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
await annotate(`QA Step Failed: ${name}`, {
|
|
61
|
+
type: 'qa-step-failed',
|
|
62
|
+
body: { name, status: 'failed' },
|
|
63
|
+
});
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
async attach(attach) {
|
|
68
|
+
const mime = attach.type ?? attach.contentType;
|
|
69
|
+
const outcome = await (0, forge_commons_1.uploadAttachmentForQa)({
|
|
70
|
+
fileName: attach.name,
|
|
71
|
+
mimeType: mime,
|
|
72
|
+
content: attach.content,
|
|
73
|
+
path: attach.path,
|
|
74
|
+
issueKey: attach.issueKey,
|
|
75
|
+
issueKeySources: [attach.issueKey, ...titleSources()],
|
|
76
|
+
});
|
|
77
|
+
await annotate(`QA Attach: ${outcome.attachment.file_name ?? attach.name ?? 'file'}`, {
|
|
78
|
+
type: 'qa-attach',
|
|
79
|
+
body: {
|
|
80
|
+
name: outcome.attachment.file_name ?? attach.name,
|
|
81
|
+
type: outcome.attachment.mime_type ?? mime,
|
|
82
|
+
size: outcome.attachment.size,
|
|
83
|
+
content_ref: outcome.attachment.content_ref,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Wrap a Vitest test body to inject `qa` helpers (uses Vitest `annotate` when present).
|
|
91
|
+
*/
|
|
92
|
+
function withQa(fn) {
|
|
93
|
+
return async (ctx) => {
|
|
94
|
+
const annotate = typeof ctx.annotate === 'function'
|
|
95
|
+
? ctx.annotate
|
|
96
|
+
: async () => undefined;
|
|
97
|
+
const qa = createQaHelpers(annotate, () => [vitestCurrentTitle(ctx)]);
|
|
98
|
+
await fn({ ...ctx, qa, annotate });
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Standalone helpers when not using withQa (no-op annotate). */
|
|
102
|
+
exports.qa = createQaHelpers(async () => undefined, () => [
|
|
103
|
+
vitestCurrentTitle(),
|
|
104
|
+
]);
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qanalyzer/forge-vitest",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "QAnalyzer Vitest reporter \u2014 ingest or file modes via @qanalyzer/forge-commons",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"qanalyzer",
|
|
7
|
+
"vitest",
|
|
8
|
+
"reporter",
|
|
9
|
+
"testing",
|
|
10
|
+
"jira"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./vitest": {
|
|
20
|
+
"types": "./dist/vitest.d.ts",
|
|
21
|
+
"default": "./dist/vitest.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"!dist/__tests__",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "npm run clean && npx tsc --project tsconfig.build.json",
|
|
35
|
+
"clean": "rm -rf dist",
|
|
36
|
+
"test": "npm run build && node --test dist/__tests__/**/*.test.js",
|
|
37
|
+
"prepublishOnly": "npm test"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@qanalyzer/forge-commons": "^1.1.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"vitest": ">=3.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"vitest": "^3.2.4"
|
|
47
|
+
},
|
|
48
|
+
"license": "Apache-2.0"
|
|
49
|
+
}
|