@qanalyzer/forge-mocha 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 +81 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/mocha.d.ts +38 -0
- package/dist/mocha.js +98 -0
- package/dist/report-builder.d.ts +23 -0
- package/dist/report-builder.js +73 -0
- package/dist/reporter.d.ts +28 -0
- package/dist/reporter.js +179 -0
- package/package.json +50 -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,81 @@
|
|
|
1
|
+
# @qanalyzer/forge-mocha
|
|
2
|
+
|
|
3
|
+
Mocha reporter for **QAnalyzer** (Jira Forge quality hub).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @qanalyzer/forge-mocha @qanalyzer/forge-commons mocha
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer: `mocha` ≥10.
|
|
12
|
+
|
|
13
|
+
## Configure
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// .mocharc.js
|
|
17
|
+
module.exports = {
|
|
18
|
+
spec: ['test/**/*.spec.js'],
|
|
19
|
+
reporter: '@qanalyzer/forge-mocha',
|
|
20
|
+
reporterOptions: {
|
|
21
|
+
// Defaults to mode=off (no credentials required)
|
|
22
|
+
// mode: 'ingest' | 'file' | 'off',
|
|
23
|
+
// projectKey: 'DEMO',
|
|
24
|
+
},
|
|
25
|
+
timeout: 10000,
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Modes
|
|
30
|
+
|
|
31
|
+
| Mode | Behavior |
|
|
32
|
+
| ---- | -------- |
|
|
33
|
+
| `off` (default) | No network / file write |
|
|
34
|
+
| `file` | Writes the ingest payload (default `./qanalyzer-results.json`) |
|
|
35
|
+
| `ingest` | POSTs the payload with `format: jest-json` |
|
|
36
|
+
|
|
37
|
+
Env (same as CLI): `QANALYZER_MODE`, `QANALYZER_PROJECT_KEY`, `QANALYZER_INGEST_URL`, `QANALYZER_INGEST_TOKEN`, `QANALYZER_LAUNCH_NAME`.
|
|
38
|
+
|
|
39
|
+
## Helpers
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
const { qa } = require('@qanalyzer/forge-mocha/mocha');
|
|
43
|
+
const assert = require('assert');
|
|
44
|
+
|
|
45
|
+
describe('JSONPlaceholder User CRUD', function () {
|
|
46
|
+
it('AUTH-101 GET all users', async function () {
|
|
47
|
+
qa.fields({ layer: 'api', severity: 'normal' });
|
|
48
|
+
await qa.step('Send GET /users', async () => {
|
|
49
|
+
const response = await fetch('https://jsonplaceholder.typicode.com/users');
|
|
50
|
+
assert.strictEqual(response.status, 200);
|
|
51
|
+
});
|
|
52
|
+
// Sync steps also supported:
|
|
53
|
+
qa.step('Validate title has issue key', () => {
|
|
54
|
+
assert.ok(true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Prefer **Jira issue keys in test titles** (no case-ID wrapper). Step hierarchy lands on `assertionResults[].meta.qa.steps`. Use `qa.attach({ contentType })` for attachment metadata (binary upload deferred).
|
|
61
|
+
|
|
62
|
+
## Dual path
|
|
63
|
+
|
|
64
|
+
**Path A — file + CLI:**
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
QANALYZER_MODE=file \
|
|
68
|
+
QANALYZER_PROJECT_KEY=DEMO \
|
|
69
|
+
npx mocha
|
|
70
|
+
npx @qanalyzer/forge-api-client --project DEMO --report qanalyzer-results.json
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Path B — reporter ingest:**
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
QANALYZER_MODE=ingest \
|
|
77
|
+
QANALYZER_PROJECT_KEY=DEMO \
|
|
78
|
+
QANALYZER_INGEST_URL=... \
|
|
79
|
+
QANALYZER_INGEST_TOKEN=... \
|
|
80
|
+
npx mocha
|
|
81
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/mocha.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic helpers for Mocha tests (FR86 / NFR26 + Phase 3 FR94 attach upload).
|
|
3
|
+
*/
|
|
4
|
+
type StepFn = () => Promise<void> | void;
|
|
5
|
+
export type QaAttachInput = {
|
|
6
|
+
name?: string;
|
|
7
|
+
contentType?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
content?: string | Buffer | Uint8Array;
|
|
10
|
+
path?: string;
|
|
11
|
+
issueKey?: string;
|
|
12
|
+
};
|
|
13
|
+
export type QaHelpers = {
|
|
14
|
+
title(value: string): void;
|
|
15
|
+
comment(value: string): void;
|
|
16
|
+
suite(value: string): void;
|
|
17
|
+
fields(values: Record<string, string>): void;
|
|
18
|
+
parameters(values: Record<string, string>): void;
|
|
19
|
+
ignore(): void;
|
|
20
|
+
step(name: string, body: StepFn): void | Promise<void>;
|
|
21
|
+
/** Sync metadata-only when no content; returns Promise when uploading. */
|
|
22
|
+
attach(attach: QaAttachInput): void | Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
export type QaMetaEntry = {
|
|
25
|
+
type: string;
|
|
26
|
+
body: unknown;
|
|
27
|
+
};
|
|
28
|
+
export type QaMochaBridge = {
|
|
29
|
+
push(entry: QaMetaEntry): void;
|
|
30
|
+
drain(): QaMetaEntry[];
|
|
31
|
+
currentTitle?: string;
|
|
32
|
+
};
|
|
33
|
+
declare global {
|
|
34
|
+
var __QA_MOCHA_BRIDGE__: QaMochaBridge | undefined;
|
|
35
|
+
}
|
|
36
|
+
export declare function drainQaMeta(): QaMetaEntry[];
|
|
37
|
+
export declare const qa: QaHelpers;
|
|
38
|
+
export {};
|
package/dist/mocha.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Programmatic helpers for Mocha tests (FR86 / NFR26 + Phase 3 FR94 attach upload).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.qa = void 0;
|
|
7
|
+
exports.drainQaMeta = drainQaMeta;
|
|
8
|
+
const forge_commons_1 = require("@qanalyzer/forge-commons");
|
|
9
|
+
const localBuffer = [];
|
|
10
|
+
function pushMeta(type, body) {
|
|
11
|
+
const entry = { type, body };
|
|
12
|
+
if (globalThis.__QA_MOCHA_BRIDGE__) {
|
|
13
|
+
globalThis.__QA_MOCHA_BRIDGE__.push(entry);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
localBuffer.push(entry);
|
|
17
|
+
}
|
|
18
|
+
function drainQaMeta() {
|
|
19
|
+
if (globalThis.__QA_MOCHA_BRIDGE__) {
|
|
20
|
+
return globalThis.__QA_MOCHA_BRIDGE__.drain();
|
|
21
|
+
}
|
|
22
|
+
const copy = [...localBuffer];
|
|
23
|
+
localBuffer.length = 0;
|
|
24
|
+
return copy;
|
|
25
|
+
}
|
|
26
|
+
function isThenable(value) {
|
|
27
|
+
return (typeof value === 'object' &&
|
|
28
|
+
value !== null &&
|
|
29
|
+
typeof value.then === 'function');
|
|
30
|
+
}
|
|
31
|
+
function currentTestTitle() {
|
|
32
|
+
return globalThis.__QA_MOCHA_BRIDGE__?.currentTitle;
|
|
33
|
+
}
|
|
34
|
+
exports.qa = {
|
|
35
|
+
title(value) {
|
|
36
|
+
pushMeta('qa-title', value);
|
|
37
|
+
},
|
|
38
|
+
comment(value) {
|
|
39
|
+
pushMeta('qa-comment', value);
|
|
40
|
+
},
|
|
41
|
+
suite(value) {
|
|
42
|
+
pushMeta('qa-suite', value);
|
|
43
|
+
},
|
|
44
|
+
fields(values) {
|
|
45
|
+
pushMeta('qa-fields', values);
|
|
46
|
+
},
|
|
47
|
+
parameters(values) {
|
|
48
|
+
pushMeta('qa-parameters', values);
|
|
49
|
+
},
|
|
50
|
+
ignore() {
|
|
51
|
+
pushMeta('qa-ignore', true);
|
|
52
|
+
},
|
|
53
|
+
step(name, body) {
|
|
54
|
+
pushMeta('qa-step', name);
|
|
55
|
+
try {
|
|
56
|
+
const result = body();
|
|
57
|
+
if (isThenable(result)) {
|
|
58
|
+
return result.then(() => {
|
|
59
|
+
pushMeta('qa-step-end', { name, status: 'passed' });
|
|
60
|
+
}, (error) => {
|
|
61
|
+
pushMeta('qa-step-failed', { name, status: 'failed' });
|
|
62
|
+
throw error;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
pushMeta('qa-step-end', { name, status: 'passed' });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
pushMeta('qa-step-failed', { name, status: 'failed' });
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
attach(attach) {
|
|
73
|
+
const mime = attach.contentType ?? attach.type;
|
|
74
|
+
const hasBinary = attach.content !== undefined || Boolean(attach.path);
|
|
75
|
+
if (!hasBinary) {
|
|
76
|
+
pushMeta('qa-attach', {
|
|
77
|
+
name: attach.name,
|
|
78
|
+
contentType: mime,
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return (0, forge_commons_1.uploadAttachmentForQa)({
|
|
83
|
+
fileName: attach.name,
|
|
84
|
+
mimeType: mime,
|
|
85
|
+
content: attach.content,
|
|
86
|
+
path: attach.path,
|
|
87
|
+
issueKey: attach.issueKey,
|
|
88
|
+
issueKeySources: [attach.issueKey, currentTestTitle()],
|
|
89
|
+
}).then((outcome) => {
|
|
90
|
+
pushMeta('qa-attach', {
|
|
91
|
+
name: outcome.attachment.file_name ?? attach.name,
|
|
92
|
+
contentType: outcome.attachment.mime_type ?? mime,
|
|
93
|
+
size: outcome.attachment.size,
|
|
94
|
+
content_ref: outcome.attachment.content_ref,
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { JestVitestJsonReport, QaMetaWire } from '@qanalyzer/forge-commons';
|
|
2
|
+
export type MochaAssertionInput = {
|
|
3
|
+
ancestorTitles: string[];
|
|
4
|
+
title: string;
|
|
5
|
+
fullName?: string;
|
|
6
|
+
status: 'passed' | 'failed' | 'pending' | 'todo';
|
|
7
|
+
duration?: number;
|
|
8
|
+
failureMessages?: string[];
|
|
9
|
+
meta?: {
|
|
10
|
+
qa?: QaMetaWire;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type MochaSpecInput = {
|
|
14
|
+
/** Spec path (e.g. test/api-crud.spec.js) */
|
|
15
|
+
name: string;
|
|
16
|
+
startTime?: number;
|
|
17
|
+
endTime?: number;
|
|
18
|
+
assertions: MochaAssertionInput[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Normalize collected Mocha specs into FR41 jest-json shape A.
|
|
22
|
+
*/
|
|
23
|
+
export declare function toJestJsonReport(specs: readonly MochaSpecInput[], startTime?: number): JestVitestJsonReport;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toJestJsonReport = toJestJsonReport;
|
|
4
|
+
function mapAssertion(a) {
|
|
5
|
+
const fullName = a.fullName ??
|
|
6
|
+
(a.ancestorTitles.length > 0
|
|
7
|
+
? `${a.ancestorTitles.join(' ')} ${a.title}`
|
|
8
|
+
: a.title);
|
|
9
|
+
const assertion = {
|
|
10
|
+
ancestorTitles: a.ancestorTitles,
|
|
11
|
+
fullName,
|
|
12
|
+
title: a.title,
|
|
13
|
+
status: a.status,
|
|
14
|
+
duration: a.duration,
|
|
15
|
+
failureMessages: a.failureMessages ?? [],
|
|
16
|
+
};
|
|
17
|
+
if (a.meta?.qa) {
|
|
18
|
+
assertion.meta = { qa: a.meta.qa };
|
|
19
|
+
}
|
|
20
|
+
return assertion;
|
|
21
|
+
}
|
|
22
|
+
function fileStatus(assertions) {
|
|
23
|
+
return assertions.some((a) => a.status === 'failed') ? 'failed' : 'passed';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalize collected Mocha specs into FR41 jest-json shape A.
|
|
27
|
+
*/
|
|
28
|
+
function toJestJsonReport(specs, startTime) {
|
|
29
|
+
const testResults = specs.map((spec) => {
|
|
30
|
+
const assertionResults = spec.assertions.map(mapAssertion);
|
|
31
|
+
return {
|
|
32
|
+
name: spec.name,
|
|
33
|
+
status: fileStatus(assertionResults),
|
|
34
|
+
startTime: spec.startTime,
|
|
35
|
+
endTime: spec.endTime,
|
|
36
|
+
assertionResults,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
let numPassedTests = 0;
|
|
40
|
+
let numFailedTests = 0;
|
|
41
|
+
let numPendingTests = 0;
|
|
42
|
+
let numTodoTests = 0;
|
|
43
|
+
for (const file of testResults) {
|
|
44
|
+
for (const a of file.assertionResults ?? []) {
|
|
45
|
+
if (a.status === 'passed')
|
|
46
|
+
numPassedTests += 1;
|
|
47
|
+
else if (a.status === 'failed')
|
|
48
|
+
numFailedTests += 1;
|
|
49
|
+
else if (a.status === 'todo')
|
|
50
|
+
numTodoTests += 1;
|
|
51
|
+
else
|
|
52
|
+
numPendingTests += 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const numTotalTests = numPassedTests + numFailedTests + numPendingTests + numTodoTests;
|
|
56
|
+
const numFailedTestSuites = testResults.filter((t) => t.status === 'failed')
|
|
57
|
+
.length;
|
|
58
|
+
const numPassedTestSuites = testResults.length - numFailedTestSuites;
|
|
59
|
+
return {
|
|
60
|
+
numTotalTestSuites: testResults.length,
|
|
61
|
+
numPassedTestSuites,
|
|
62
|
+
numFailedTestSuites,
|
|
63
|
+
numPendingTestSuites: 0,
|
|
64
|
+
numTotalTests,
|
|
65
|
+
numPassedTests,
|
|
66
|
+
numFailedTests,
|
|
67
|
+
numPendingTests,
|
|
68
|
+
numTodoTests,
|
|
69
|
+
startTime,
|
|
70
|
+
success: numFailedTests === 0,
|
|
71
|
+
testResults,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { reporters, Runner, type MochaOptions } from 'mocha';
|
|
2
|
+
import { type OptionsType } from '@qanalyzer/forge-commons';
|
|
3
|
+
export type MochaQaOptions = OptionsType;
|
|
4
|
+
export type MochaQaReporterOptions = Omit<MochaOptions, 'reporterOptions'> & {
|
|
5
|
+
reporterOptions?: MochaQaOptions;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Mocha custom reporter for QAnalyzer.
|
|
9
|
+
*
|
|
10
|
+
* Configure: `.mocharc.js` → `reporter: '@qanalyzer/forge-mocha'`
|
|
11
|
+
* Options: `reporterOptions: { mode: 'ingest' | 'file' | 'off', … }`
|
|
12
|
+
* Env: `QANALYZER_MODE`, `QANALYZER_PROJECT_KEY`, …
|
|
13
|
+
*
|
|
14
|
+
* Helpers from `@qanalyzer/forge-mocha/mocha` forward metadata via a global bridge.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MochaQaReporter extends reporters.Spec {
|
|
17
|
+
private readonly options;
|
|
18
|
+
private readonly bridgeBuffer;
|
|
19
|
+
private readonly byFile;
|
|
20
|
+
private readonly runStart;
|
|
21
|
+
private publishPromise;
|
|
22
|
+
constructor(runner: Runner, options?: MochaQaReporterOptions);
|
|
23
|
+
/** Await in-process publish (tests / programmatic runs). */
|
|
24
|
+
waitForPublish(): Promise<void>;
|
|
25
|
+
private installBridge;
|
|
26
|
+
private record;
|
|
27
|
+
private publish;
|
|
28
|
+
}
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MochaQaReporter = void 0;
|
|
4
|
+
const mocha_1 = require("mocha");
|
|
5
|
+
const forge_commons_1 = require("@qanalyzer/forge-commons");
|
|
6
|
+
const report_builder_1 = require("./report-builder");
|
|
7
|
+
function mapStatus(state) {
|
|
8
|
+
if (state === 'failed')
|
|
9
|
+
return 'failed';
|
|
10
|
+
if (state === 'pending')
|
|
11
|
+
return 'pending';
|
|
12
|
+
return 'passed';
|
|
13
|
+
}
|
|
14
|
+
function ancestorTitles(test) {
|
|
15
|
+
try {
|
|
16
|
+
const path = typeof test.titlePath === 'function' ? test.titlePath() : [];
|
|
17
|
+
if (path.length > 1)
|
|
18
|
+
return path.slice(0, -1);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// fall through
|
|
22
|
+
}
|
|
23
|
+
const titles = [];
|
|
24
|
+
let parent = test.parent;
|
|
25
|
+
while (parent && !parent.root) {
|
|
26
|
+
if (parent.title)
|
|
27
|
+
titles.unshift(parent.title);
|
|
28
|
+
parent = parent.parent;
|
|
29
|
+
}
|
|
30
|
+
return titles;
|
|
31
|
+
}
|
|
32
|
+
function specFileName(test) {
|
|
33
|
+
const fromTest = test.file;
|
|
34
|
+
if (fromTest)
|
|
35
|
+
return fromTest;
|
|
36
|
+
let parent = test.parent;
|
|
37
|
+
while (parent) {
|
|
38
|
+
const file = parent.file;
|
|
39
|
+
if (file)
|
|
40
|
+
return file;
|
|
41
|
+
parent = parent.parent;
|
|
42
|
+
}
|
|
43
|
+
return 'unknown';
|
|
44
|
+
}
|
|
45
|
+
function failureMessages(test) {
|
|
46
|
+
const err = test.err;
|
|
47
|
+
if (!err)
|
|
48
|
+
return [];
|
|
49
|
+
const msg = err.stack || err.message;
|
|
50
|
+
return msg ? [msg] : [];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Mocha custom reporter for QAnalyzer.
|
|
54
|
+
*
|
|
55
|
+
* Configure: `.mocharc.js` → `reporter: '@qanalyzer/forge-mocha'`
|
|
56
|
+
* Options: `reporterOptions: { mode: 'ingest' | 'file' | 'off', … }`
|
|
57
|
+
* Env: `QANALYZER_MODE`, `QANALYZER_PROJECT_KEY`, …
|
|
58
|
+
*
|
|
59
|
+
* Helpers from `@qanalyzer/forge-mocha/mocha` forward metadata via a global bridge.
|
|
60
|
+
*/
|
|
61
|
+
class MochaQaReporter extends mocha_1.reporters.Spec {
|
|
62
|
+
options;
|
|
63
|
+
bridgeBuffer = [];
|
|
64
|
+
byFile = new Map();
|
|
65
|
+
runStart = Date.now();
|
|
66
|
+
publishPromise = null;
|
|
67
|
+
constructor(runner, options = {}) {
|
|
68
|
+
super(runner, options);
|
|
69
|
+
this.options = options.reporterOptions ?? {};
|
|
70
|
+
this.installBridge();
|
|
71
|
+
runner.on(mocha_1.Runner.constants.EVENT_TEST_BEGIN, (test) => {
|
|
72
|
+
this.bridgeBuffer.length = 0;
|
|
73
|
+
if (globalThis.__QA_MOCHA_BRIDGE__) {
|
|
74
|
+
globalThis.__QA_MOCHA_BRIDGE__.currentTitle = test.fullTitle?.() ?? test.title;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
runner.on(mocha_1.Runner.constants.EVENT_TEST_PASS, (test) => {
|
|
78
|
+
this.record(test, 'passed');
|
|
79
|
+
});
|
|
80
|
+
runner.on(mocha_1.Runner.constants.EVENT_TEST_FAIL, (test) => {
|
|
81
|
+
this.record(test, 'failed');
|
|
82
|
+
});
|
|
83
|
+
runner.on(mocha_1.Runner.constants.EVENT_TEST_PENDING, (test) => {
|
|
84
|
+
this.record(test, 'pending');
|
|
85
|
+
});
|
|
86
|
+
runner.once(mocha_1.Runner.constants.EVENT_RUN_END, () => {
|
|
87
|
+
this.publishPromise = this.publish();
|
|
88
|
+
void this.publishPromise.catch(() => {
|
|
89
|
+
// Never fail the Mocha run because of reporter publish errors
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** Await in-process publish (tests / programmatic runs). */
|
|
94
|
+
async waitForPublish() {
|
|
95
|
+
if (this.publishPromise)
|
|
96
|
+
await this.publishPromise;
|
|
97
|
+
}
|
|
98
|
+
installBridge() {
|
|
99
|
+
const bridge = {
|
|
100
|
+
push: (entry) => {
|
|
101
|
+
this.bridgeBuffer.push(entry);
|
|
102
|
+
},
|
|
103
|
+
drain: () => {
|
|
104
|
+
const copy = [...this.bridgeBuffer];
|
|
105
|
+
this.bridgeBuffer.length = 0;
|
|
106
|
+
return copy;
|
|
107
|
+
},
|
|
108
|
+
currentTitle: undefined,
|
|
109
|
+
};
|
|
110
|
+
globalThis.__QA_MOCHA_BRIDGE__ = bridge;
|
|
111
|
+
}
|
|
112
|
+
record(test, state) {
|
|
113
|
+
try {
|
|
114
|
+
const entries = this.bridgeBuffer.splice(0, this.bridgeBuffer.length);
|
|
115
|
+
const wire = (0, forge_commons_1.qaMetaFromEntries)(entries, {
|
|
116
|
+
framework: 'mocha',
|
|
117
|
+
reporter: '@qanalyzer/forge-mocha',
|
|
118
|
+
});
|
|
119
|
+
const ancestors = ancestorTitles(test);
|
|
120
|
+
const assertion = {
|
|
121
|
+
ancestorTitles: ancestors,
|
|
122
|
+
title: test.title,
|
|
123
|
+
fullName: ancestors.length > 0 ? `${ancestors.join(' ')} ${test.title}` : test.title,
|
|
124
|
+
status: mapStatus(state ?? test.state),
|
|
125
|
+
duration: test.duration ?? undefined,
|
|
126
|
+
failureMessages: state === 'failed' ? failureMessages(test) : [],
|
|
127
|
+
};
|
|
128
|
+
if (wire) {
|
|
129
|
+
assertion.meta = { qa: wire };
|
|
130
|
+
}
|
|
131
|
+
const file = specFileName(test);
|
|
132
|
+
const list = this.byFile.get(file) ?? [];
|
|
133
|
+
list.push(assertion);
|
|
134
|
+
this.byFile.set(file, list);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Never fail the Mocha run
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async publish() {
|
|
141
|
+
try {
|
|
142
|
+
forge_commons_1.QAnalyzerReporter.resetInstance();
|
|
143
|
+
const reporter = forge_commons_1.QAnalyzerReporter.getInstance({
|
|
144
|
+
...this.options,
|
|
145
|
+
mode: this.options.mode ?? forge_commons_1.ModeEnum.off,
|
|
146
|
+
frameworkName: this.options.frameworkName ?? 'mocha',
|
|
147
|
+
reporterName: this.options.reporterName ?? '@qanalyzer/forge-mocha',
|
|
148
|
+
frameworkPackage: this.options.frameworkPackage ?? 'mocha',
|
|
149
|
+
});
|
|
150
|
+
const mode = reporter.getConfig().mode ?? forge_commons_1.ModeEnum.off;
|
|
151
|
+
if (mode === forge_commons_1.ModeEnum.off) {
|
|
152
|
+
this.byFile.clear();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const specs = [];
|
|
156
|
+
for (const [name, assertions] of this.byFile) {
|
|
157
|
+
if (assertions.length === 0)
|
|
158
|
+
continue;
|
|
159
|
+
specs.push({
|
|
160
|
+
name,
|
|
161
|
+
startTime: this.runStart,
|
|
162
|
+
endTime: Date.now(),
|
|
163
|
+
assertions,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
this.byFile.clear();
|
|
167
|
+
const report = (0, report_builder_1.toJestJsonReport)(specs, this.runStart);
|
|
168
|
+
await reporter.publishReport(report, {
|
|
169
|
+
format: 'jest-json',
|
|
170
|
+
launchName: this.options.launchName,
|
|
171
|
+
projectKey: this.options.projectKey,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
// Never fail the Mocha run because of reporter publish errors
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.MochaQaReporter = MochaQaReporter;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qanalyzer/forge-mocha",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "QAnalyzer Mocha reporter \u2014 ingest or file modes via @qanalyzer/forge-commons",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"qanalyzer",
|
|
7
|
+
"mocha",
|
|
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
|
+
"./mocha": {
|
|
20
|
+
"types": "./dist/mocha.d.ts",
|
|
21
|
+
"default": "./dist/mocha.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
|
+
"mocha": ">=10.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/mocha": "^10.0.10",
|
|
47
|
+
"mocha": "^11.3.0"
|
|
48
|
+
},
|
|
49
|
+
"license": "Apache-2.0"
|
|
50
|
+
}
|