@qanalyzer/forge-cucumberjs 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 +61 -0
- package/dist/formatter.d.ts +26 -0
- package/dist/formatter.js +106 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/modules/event-storage.d.ts +49 -0
- package/dist/modules/event-storage.js +163 -0
- package/dist/modules/tag-parser.d.ts +22 -0
- package/dist/modules/tag-parser.js +88 -0
- package/dist/report-builder.d.ts +45 -0
- package/dist/report-builder.js +233 -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,61 @@
|
|
|
1
|
+
# @qanalyzer/forge-cucumberjs
|
|
2
|
+
|
|
3
|
+
CucumberJS formatter for **QAnalyzer** (Jira Forge quality hub).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @qanalyzer/forge-cucumberjs @qanalyzer/forge-commons @cucumber/cucumber
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer: `@cucumber/cucumber` ≥10.
|
|
12
|
+
|
|
13
|
+
## Configure
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// cucumber.js
|
|
17
|
+
module.exports = {
|
|
18
|
+
default: {
|
|
19
|
+
format: ['progress', '@qanalyzer/forge-cucumberjs'],
|
|
20
|
+
require: ['step_definitions/**/*.js'],
|
|
21
|
+
// formatOptions: { mode: 'ingest', projectKey: 'DEMO' },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Modes
|
|
27
|
+
|
|
28
|
+
| Mode | Behavior |
|
|
29
|
+
| ---- | -------- |
|
|
30
|
+
| `off` (default) | No network / file write |
|
|
31
|
+
| `file` | Writes the ingest payload (default `./qanalyzer-results.json`) |
|
|
32
|
+
| `ingest` | POSTs the payload with `format: jest-json` |
|
|
33
|
+
|
|
34
|
+
Env: `QANALYZER_MODE`, `QANALYZER_PROJECT_KEY`, `QANALYZER_INGEST_URL`, `QANALYZER_INGEST_TOKEN`, `QANALYZER_LAUNCH_NAME`.
|
|
35
|
+
|
|
36
|
+
## Metadata (tags only)
|
|
37
|
+
|
|
38
|
+
No programmatic `qa` import — use Gherkin tags:
|
|
39
|
+
|
|
40
|
+
| Tag | Effect |
|
|
41
|
+
| --- | ------ |
|
|
42
|
+
| `@AUTH-101` | Issue key; also prefer keys in scenario titles |
|
|
43
|
+
| `@QaTitle=Custom_title` | Display title (underscores → spaces) |
|
|
44
|
+
| `@QaSuite=API\tUsers\tRead` | Suite hierarchy |
|
|
45
|
+
| `@QaFields={"layer":"api"}` | Custom fields JSON |
|
|
46
|
+
| `@QaParameters={"userId":"1"}` | Parameters JSON |
|
|
47
|
+
| `@QaIgnore` | Skip reporting |
|
|
48
|
+
|
|
49
|
+
Given/When/Then steps become `meta.qa.steps`. Use `function()` step defs for World (`this`).
|
|
50
|
+
|
|
51
|
+
## Dual path
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# file
|
|
55
|
+
QANALYZER_MODE=file QANALYZER_PROJECT_KEY=DEMO npx cucumber-js
|
|
56
|
+
|
|
57
|
+
# ingest
|
|
58
|
+
QANALYZER_MODE=ingest QANALYZER_PROJECT_KEY=DEMO \
|
|
59
|
+
QANALYZER_INGEST_URL=... QANALYZER_INGEST_TOKEN=... \
|
|
60
|
+
npx cucumber-js
|
|
61
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Formatter, type IFormatterOptions } from '@cucumber/cucumber';
|
|
2
|
+
import { type OptionsType } from '@qanalyzer/forge-commons';
|
|
3
|
+
export type CucumberQaOptions = OptionsType;
|
|
4
|
+
export type CucumberQaFormatterOptions = IFormatterOptions & CucumberQaOptions;
|
|
5
|
+
/**
|
|
6
|
+
* CucumberJS custom formatter for QAnalyzer.
|
|
7
|
+
*
|
|
8
|
+
* Configure (`cucumber.js`):
|
|
9
|
+
* format: ['progress', '@qanalyzer/forge-cucumberjs']
|
|
10
|
+
*
|
|
11
|
+
* Modes via env (`QANALYZER_MODE`) or formatOptions.
|
|
12
|
+
* Helpers are tag-based (`@QaTitle`, `@QaSuite`, `@QaIgnore`, `@AUTH-101`) — no programmatic import (FR54).
|
|
13
|
+
* `this.attach()` → envelope.attachment → optional Forge upload (FR58).
|
|
14
|
+
*/
|
|
15
|
+
export declare class CucumberQaFormatter extends Formatter {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly storage;
|
|
18
|
+
private readonly byUri;
|
|
19
|
+
private readonly runStart;
|
|
20
|
+
private readonly pendingScenarios;
|
|
21
|
+
private publishPromise;
|
|
22
|
+
constructor(options: CucumberQaFormatterOptions);
|
|
23
|
+
waitForPublish(): Promise<void>;
|
|
24
|
+
private onEnvelope;
|
|
25
|
+
private publish;
|
|
26
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CucumberQaFormatter = void 0;
|
|
4
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
+
const forge_commons_1 = require("@qanalyzer/forge-commons");
|
|
6
|
+
const event_storage_1 = require("./modules/event-storage");
|
|
7
|
+
const report_builder_1 = require("./report-builder");
|
|
8
|
+
/**
|
|
9
|
+
* CucumberJS custom formatter for QAnalyzer.
|
|
10
|
+
*
|
|
11
|
+
* Configure (`cucumber.js`):
|
|
12
|
+
* format: ['progress', '@qanalyzer/forge-cucumberjs']
|
|
13
|
+
*
|
|
14
|
+
* Modes via env (`QANALYZER_MODE`) or formatOptions.
|
|
15
|
+
* Helpers are tag-based (`@QaTitle`, `@QaSuite`, `@QaIgnore`, `@AUTH-101`) — no programmatic import (FR54).
|
|
16
|
+
* `this.attach()` → envelope.attachment → optional Forge upload (FR58).
|
|
17
|
+
*/
|
|
18
|
+
class CucumberQaFormatter extends cucumber_1.Formatter {
|
|
19
|
+
options;
|
|
20
|
+
storage = new event_storage_1.EventStorage();
|
|
21
|
+
byUri = new Map();
|
|
22
|
+
runStart = Date.now();
|
|
23
|
+
pendingScenarios = [];
|
|
24
|
+
publishPromise = null;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
const { mode, projectKey, debug, launchName, frameworkPackage, frameworkName, reporterName, fallback, file, ...formatterOptions } = options;
|
|
27
|
+
super(formatterOptions);
|
|
28
|
+
this.options = {
|
|
29
|
+
mode,
|
|
30
|
+
projectKey,
|
|
31
|
+
debug,
|
|
32
|
+
launchName,
|
|
33
|
+
file,
|
|
34
|
+
frameworkPackage: frameworkPackage ?? '@cucumber/cucumber',
|
|
35
|
+
frameworkName: frameworkName ?? 'cucumberjs',
|
|
36
|
+
reporterName: reporterName ?? '@qanalyzer/forge-cucumberjs',
|
|
37
|
+
fallback,
|
|
38
|
+
};
|
|
39
|
+
options.eventBroadcaster.on('envelope', (envelope) => {
|
|
40
|
+
this.onEnvelope(envelope);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async waitForPublish() {
|
|
44
|
+
if (this.publishPromise)
|
|
45
|
+
await this.publishPromise;
|
|
46
|
+
}
|
|
47
|
+
onEnvelope(envelope) {
|
|
48
|
+
try {
|
|
49
|
+
if (envelope.testCaseFinished) {
|
|
50
|
+
const converted = this.storage.convertFinished(envelope.testCaseFinished);
|
|
51
|
+
if (converted) {
|
|
52
|
+
this.pendingScenarios.push((0, report_builder_1.scenarioToAssertionAsync)(converted)
|
|
53
|
+
.then((assertion) => {
|
|
54
|
+
if (!assertion)
|
|
55
|
+
return;
|
|
56
|
+
const list = this.byUri.get(converted.uri) ?? [];
|
|
57
|
+
list.push(assertion);
|
|
58
|
+
this.byUri.set(converted.uri, list);
|
|
59
|
+
})
|
|
60
|
+
.catch(() => {
|
|
61
|
+
// Never fail the Cucumber run
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.storage.ingest(envelope);
|
|
67
|
+
}
|
|
68
|
+
if (envelope.testRunFinished) {
|
|
69
|
+
this.publishPromise = this.publish();
|
|
70
|
+
void this.publishPromise.catch(() => {
|
|
71
|
+
// Never fail the Cucumber run
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Never fail the Cucumber run
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async publish() {
|
|
80
|
+
try {
|
|
81
|
+
await Promise.all(this.pendingScenarios);
|
|
82
|
+
forge_commons_1.QAnalyzerReporter.resetInstance();
|
|
83
|
+
const reporter = forge_commons_1.QAnalyzerReporter.getInstance({
|
|
84
|
+
...this.options,
|
|
85
|
+
mode: this.options.mode ?? forge_commons_1.ModeEnum.off,
|
|
86
|
+
});
|
|
87
|
+
const mode = reporter.getConfig().mode ?? forge_commons_1.ModeEnum.off;
|
|
88
|
+
if (mode === forge_commons_1.ModeEnum.off) {
|
|
89
|
+
this.byUri.clear();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const specs = (0, report_builder_1.specsFromAssertions)(this.byUri, this.runStart, Date.now());
|
|
93
|
+
this.byUri.clear();
|
|
94
|
+
const report = (0, report_builder_1.toJestJsonReport)(specs, this.runStart);
|
|
95
|
+
await reporter.publishReport(report, {
|
|
96
|
+
format: 'jest-json',
|
|
97
|
+
launchName: this.options.launchName,
|
|
98
|
+
projectKey: this.options.projectKey,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Never fail the Cucumber run
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.CucumberQaFormatter = CucumberQaFormatter;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Envelope, Pickle, TestCaseFinished } from '@cucumber/messages';
|
|
2
|
+
export type FeatureInfo = {
|
|
3
|
+
name: string;
|
|
4
|
+
uri: string;
|
|
5
|
+
};
|
|
6
|
+
export type FinishedStep = {
|
|
7
|
+
pickleStepId: string | undefined;
|
|
8
|
+
text: string;
|
|
9
|
+
status: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
};
|
|
13
|
+
/** Captured Cucumber `this.attach()` payload (envelope.attachment). */
|
|
14
|
+
export type StoredAttachment = {
|
|
15
|
+
body: string;
|
|
16
|
+
contentEncoding: string;
|
|
17
|
+
mediaType: string;
|
|
18
|
+
fileName?: string;
|
|
19
|
+
testCaseStartedId?: string;
|
|
20
|
+
testStepId?: string;
|
|
21
|
+
};
|
|
22
|
+
export type ConvertedScenario = {
|
|
23
|
+
featureName: string;
|
|
24
|
+
uri: string;
|
|
25
|
+
title: string;
|
|
26
|
+
pickle: Pickle;
|
|
27
|
+
status: 'passed' | 'failed' | 'pending';
|
|
28
|
+
durationMs: number;
|
|
29
|
+
failureMessages: string[];
|
|
30
|
+
steps: FinishedStep[];
|
|
31
|
+
attachments: StoredAttachment[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Collects Cucumber message envelopes until a scenario can be converted.
|
|
35
|
+
*/
|
|
36
|
+
export declare class EventStorage {
|
|
37
|
+
private readonly featuresByUri;
|
|
38
|
+
private readonly pickles;
|
|
39
|
+
private readonly testCases;
|
|
40
|
+
private readonly testCaseStarts;
|
|
41
|
+
private readonly stepFinishedByTestStepId;
|
|
42
|
+
private readonly featureNameByScenarioAstId;
|
|
43
|
+
private readonly attachmentsByStartedId;
|
|
44
|
+
ingest(envelope: Envelope): void;
|
|
45
|
+
convertFinished(finished: TestCaseFinished): ConvertedScenario | undefined;
|
|
46
|
+
private addAttachment;
|
|
47
|
+
private addGherkin;
|
|
48
|
+
private featureNameForPickle;
|
|
49
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventStorage = void 0;
|
|
4
|
+
function durationMs(ts) {
|
|
5
|
+
if (!ts)
|
|
6
|
+
return 0;
|
|
7
|
+
const seconds = Number(ts.seconds ?? 0);
|
|
8
|
+
const nanos = Number(ts.nanos ?? 0);
|
|
9
|
+
return seconds * 1000 + Math.round(nanos / 1e6);
|
|
10
|
+
}
|
|
11
|
+
function timestampMs(ts) {
|
|
12
|
+
if (!ts)
|
|
13
|
+
return Date.now();
|
|
14
|
+
const seconds = Number(ts.seconds ?? 0);
|
|
15
|
+
const nanos = Number(ts.nanos ?? 0);
|
|
16
|
+
return seconds * 1000 + Math.round(nanos / 1e6);
|
|
17
|
+
}
|
|
18
|
+
function toStoredAttachment(attachment) {
|
|
19
|
+
return {
|
|
20
|
+
body: attachment.body ?? '',
|
|
21
|
+
contentEncoding: String(attachment.contentEncoding ?? 'IDENTITY'),
|
|
22
|
+
mediaType: attachment.mediaType ?? 'application/octet-stream',
|
|
23
|
+
fileName: attachment.fileName,
|
|
24
|
+
testCaseStartedId: attachment.testCaseStartedId,
|
|
25
|
+
testStepId: attachment.testStepId,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Collects Cucumber message envelopes until a scenario can be converted.
|
|
30
|
+
*/
|
|
31
|
+
class EventStorage {
|
|
32
|
+
featuresByUri = new Map();
|
|
33
|
+
pickles = new Map();
|
|
34
|
+
testCases = new Map();
|
|
35
|
+
testCaseStarts = new Map();
|
|
36
|
+
stepFinishedByTestStepId = new Map();
|
|
37
|
+
featureNameByScenarioAstId = new Map();
|
|
38
|
+
attachmentsByStartedId = new Map();
|
|
39
|
+
ingest(envelope) {
|
|
40
|
+
if (envelope.gherkinDocument) {
|
|
41
|
+
this.addGherkin(envelope.gherkinDocument);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (envelope.pickle) {
|
|
45
|
+
this.pickles.set(envelope.pickle.id, envelope.pickle);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (envelope.testCase) {
|
|
49
|
+
this.testCases.set(envelope.testCase.id, envelope.testCase);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (envelope.testCaseStarted) {
|
|
53
|
+
this.testCaseStarts.set(envelope.testCaseStarted.id, envelope.testCaseStarted);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (envelope.testStepFinished) {
|
|
57
|
+
this.stepFinishedByTestStepId.set(envelope.testStepFinished.testStepId, envelope.testStepFinished);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (envelope.attachment) {
|
|
61
|
+
this.addAttachment(envelope.attachment);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
convertFinished(finished) {
|
|
65
|
+
const started = this.testCaseStarts.get(finished.testCaseStartedId);
|
|
66
|
+
if (!started)
|
|
67
|
+
return undefined;
|
|
68
|
+
const testCase = this.testCases.get(started.testCaseId);
|
|
69
|
+
if (!testCase)
|
|
70
|
+
return undefined;
|
|
71
|
+
const pickle = this.pickles.get(testCase.pickleId);
|
|
72
|
+
if (!pickle)
|
|
73
|
+
return undefined;
|
|
74
|
+
const uri = pickle.uri ?? 'unknown.feature';
|
|
75
|
+
const feature = this.featuresByUri.get(uri)?.name ??
|
|
76
|
+
this.featureNameForPickle(pickle) ??
|
|
77
|
+
'Feature';
|
|
78
|
+
const steps = [];
|
|
79
|
+
const failureMessages = [];
|
|
80
|
+
let anyFailed = false;
|
|
81
|
+
let anyPending = false;
|
|
82
|
+
for (const testStep of testCase.testSteps ?? []) {
|
|
83
|
+
if (!testStep.pickleStepId)
|
|
84
|
+
continue; // hook steps
|
|
85
|
+
const finishedStep = this.stepFinishedByTestStepId.get(testStep.id);
|
|
86
|
+
if (!finishedStep)
|
|
87
|
+
continue;
|
|
88
|
+
const pickleStep = pickle.steps?.find((s) => s.id === testStep.pickleStepId);
|
|
89
|
+
const status = String(finishedStep.testStepResult?.status ?? 'UNKNOWN');
|
|
90
|
+
const message = finishedStep.testStepResult?.message ?? undefined;
|
|
91
|
+
steps.push({
|
|
92
|
+
pickleStepId: testStep.pickleStepId,
|
|
93
|
+
text: pickleStep?.text ?? testStep.pickleStepId,
|
|
94
|
+
status,
|
|
95
|
+
message,
|
|
96
|
+
durationMs: durationMs(finishedStep.testStepResult?.duration),
|
|
97
|
+
});
|
|
98
|
+
if (status === 'FAILED' || status === 'AMBIGUOUS') {
|
|
99
|
+
anyFailed = true;
|
|
100
|
+
if (message)
|
|
101
|
+
failureMessages.push(message);
|
|
102
|
+
}
|
|
103
|
+
else if (status === 'PENDING' ||
|
|
104
|
+
status === 'UNDEFINED' ||
|
|
105
|
+
status === 'SKIPPED') {
|
|
106
|
+
anyPending = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const startMs = timestampMs(started.timestamp);
|
|
110
|
+
const endMs = timestampMs(finished.timestamp);
|
|
111
|
+
let status = 'passed';
|
|
112
|
+
if (anyFailed)
|
|
113
|
+
status = 'failed';
|
|
114
|
+
else if (anyPending && steps.every((s) => s.status !== 'PASSED')) {
|
|
115
|
+
status = 'pending';
|
|
116
|
+
}
|
|
117
|
+
else if (anyPending && !anyFailed) {
|
|
118
|
+
// Background skips alone — treat as passed if at least one passed step
|
|
119
|
+
status = steps.some((s) => s.status === 'PASSED') ? 'passed' : 'pending';
|
|
120
|
+
}
|
|
121
|
+
const attachments = this.attachmentsByStartedId.get(finished.testCaseStartedId) ?? [];
|
|
122
|
+
this.attachmentsByStartedId.delete(finished.testCaseStartedId);
|
|
123
|
+
return {
|
|
124
|
+
featureName: feature,
|
|
125
|
+
uri,
|
|
126
|
+
title: pickle.name,
|
|
127
|
+
pickle,
|
|
128
|
+
status,
|
|
129
|
+
durationMs: Math.max(0, endMs - startMs),
|
|
130
|
+
failureMessages,
|
|
131
|
+
steps,
|
|
132
|
+
attachments,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
addAttachment(attachment) {
|
|
136
|
+
const startedId = attachment.testCaseStartedId;
|
|
137
|
+
if (!startedId)
|
|
138
|
+
return;
|
|
139
|
+
const list = this.attachmentsByStartedId.get(startedId) ?? [];
|
|
140
|
+
list.push(toStoredAttachment(attachment));
|
|
141
|
+
this.attachmentsByStartedId.set(startedId, list);
|
|
142
|
+
}
|
|
143
|
+
addGherkin(doc) {
|
|
144
|
+
if (!doc.feature)
|
|
145
|
+
return;
|
|
146
|
+
const uri = doc.uri ?? 'unknown.feature';
|
|
147
|
+
this.featuresByUri.set(uri, { name: doc.feature.name, uri });
|
|
148
|
+
for (const child of doc.feature.children ?? []) {
|
|
149
|
+
if (child.scenario?.id) {
|
|
150
|
+
this.featureNameByScenarioAstId.set(child.scenario.id, doc.feature.name);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
featureNameForPickle(pickle) {
|
|
155
|
+
for (const astId of pickle.astNodeIds ?? []) {
|
|
156
|
+
const name = this.featureNameByScenarioAstId.get(astId);
|
|
157
|
+
if (name)
|
|
158
|
+
return name;
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.EventStorage = EventStorage;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PickleTag } from '@cucumber/messages';
|
|
2
|
+
/** Parsed Gherkin tags → QAnalyzer meta (FR52). */
|
|
3
|
+
export type CucumberQaTagMeta = {
|
|
4
|
+
title: string | null;
|
|
5
|
+
ignore: boolean;
|
|
6
|
+
suite: string | null;
|
|
7
|
+
fields: Record<string, string>;
|
|
8
|
+
parameters: Record<string, string>;
|
|
9
|
+
/** Issue keys from tags like @AUTH-101 (FR51). */
|
|
10
|
+
issueKeys: string[];
|
|
11
|
+
};
|
|
12
|
+
type TagLike = Pick<PickleTag, 'name'> | {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Parse `@Qa*` and issue-key tags from a pickle.
|
|
17
|
+
* No competitor tag names — destination is Jira.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseQaTags(tags: readonly TagLike[]): CucumberQaTagMeta;
|
|
20
|
+
/** Prefer tag title; else prefix issue keys onto pickle name when missing. */
|
|
21
|
+
export declare function resolveScenarioTitle(pickleName: string, meta: CucumberQaTagMeta): string;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseQaTags = parseQaTags;
|
|
4
|
+
exports.resolveScenarioTitle = resolveScenarioTitle;
|
|
5
|
+
const titleRe = /^@[Qq]a[Tt]itle=(.+)$/;
|
|
6
|
+
const ignoreRe = /^@[Qq]a[Ii]gnore$/;
|
|
7
|
+
const suiteRe = /^@[Qq]a[Ss]uite=(.+)$/;
|
|
8
|
+
const fieldsRe = /^@[Qq]a[Ff]ields=(.+)$/;
|
|
9
|
+
const parametersRe = /^@[Qq]a[Pp]arameters=(.+)$/;
|
|
10
|
+
const issueKeyRe = /^@([A-Z][A-Z0-9]+-\d+)$/;
|
|
11
|
+
function normalizeJsonString(value) {
|
|
12
|
+
return value.replace(/'/g, '"');
|
|
13
|
+
}
|
|
14
|
+
function tryParseRecord(raw) {
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(normalizeJsonString(raw));
|
|
17
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
const out = {};
|
|
21
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
22
|
+
out[k] = String(v);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse `@Qa*` and issue-key tags from a pickle.
|
|
32
|
+
* No competitor tag names — destination is Jira.
|
|
33
|
+
*/
|
|
34
|
+
function parseQaTags(tags) {
|
|
35
|
+
const meta = {
|
|
36
|
+
title: null,
|
|
37
|
+
ignore: false,
|
|
38
|
+
suite: null,
|
|
39
|
+
fields: {},
|
|
40
|
+
parameters: {},
|
|
41
|
+
issueKeys: [],
|
|
42
|
+
};
|
|
43
|
+
for (const tag of tags) {
|
|
44
|
+
const name = tag.name;
|
|
45
|
+
if (ignoreRe.test(name)) {
|
|
46
|
+
meta.ignore = true;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const titleMatch = titleRe.exec(name);
|
|
50
|
+
if (titleMatch?.[1]) {
|
|
51
|
+
meta.title = titleMatch[1].replace(/_/g, ' ');
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const suiteMatch = suiteRe.exec(name);
|
|
55
|
+
if (suiteMatch?.[1]) {
|
|
56
|
+
meta.suite = suiteMatch[1];
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const fieldsMatch = fieldsRe.exec(name);
|
|
60
|
+
if (fieldsMatch?.[1]) {
|
|
61
|
+
meta.fields = { ...meta.fields, ...tryParseRecord(fieldsMatch[1]) };
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const paramsMatch = parametersRe.exec(name);
|
|
65
|
+
if (paramsMatch?.[1]) {
|
|
66
|
+
meta.parameters = {
|
|
67
|
+
...meta.parameters,
|
|
68
|
+
...tryParseRecord(paramsMatch[1]),
|
|
69
|
+
};
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const issueMatch = issueKeyRe.exec(name);
|
|
73
|
+
if (issueMatch?.[1]) {
|
|
74
|
+
meta.issueKeys.push(issueMatch[1]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return meta;
|
|
78
|
+
}
|
|
79
|
+
/** Prefer tag title; else prefix issue keys onto pickle name when missing. */
|
|
80
|
+
function resolveScenarioTitle(pickleName, meta) {
|
|
81
|
+
if (meta.title)
|
|
82
|
+
return meta.title;
|
|
83
|
+
const key = meta.issueKeys[0];
|
|
84
|
+
if (key && !pickleName.includes(key)) {
|
|
85
|
+
return `${key} ${pickleName}`;
|
|
86
|
+
}
|
|
87
|
+
return pickleName;
|
|
88
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { JestVitestJsonReport, QaMetaWire } from '@qanalyzer/forge-commons';
|
|
2
|
+
import type { ConvertedScenario } from './modules/event-storage';
|
|
3
|
+
export type CucumberAssertionInput = {
|
|
4
|
+
ancestorTitles: string[];
|
|
5
|
+
title: string;
|
|
6
|
+
fullName?: string;
|
|
7
|
+
status: 'passed' | 'failed' | 'pending' | 'todo';
|
|
8
|
+
duration?: number;
|
|
9
|
+
failureMessages?: string[];
|
|
10
|
+
meta?: {
|
|
11
|
+
qa?: QaMetaWire;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type CucumberSpecInput = {
|
|
15
|
+
name: string;
|
|
16
|
+
startTime?: number;
|
|
17
|
+
endTime?: number;
|
|
18
|
+
assertions: CucumberAssertionInput[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Upload Cucumber attachments (FR58). Never throws — missing key / oversize /
|
|
22
|
+
* config → metadata-only wire entries.
|
|
23
|
+
*/
|
|
24
|
+
export declare function uploadScenarioAttachments(scenario: ConvertedScenario, title: string, tagIssueKeys: readonly string[]): Promise<Array<{
|
|
25
|
+
type: string;
|
|
26
|
+
body: unknown;
|
|
27
|
+
}>>;
|
|
28
|
+
/**
|
|
29
|
+
* Convert a finished Cucumber scenario into one FR41 assertion (or null if @QaIgnore).
|
|
30
|
+
* Pass pre-built attachEntries from {@link uploadScenarioAttachments} when available.
|
|
31
|
+
*/
|
|
32
|
+
export declare function scenarioToAssertion(scenario: ConvertedScenario, attachEntries?: Array<{
|
|
33
|
+
type: string;
|
|
34
|
+
body: unknown;
|
|
35
|
+
}>): CucumberAssertionInput | null;
|
|
36
|
+
/**
|
|
37
|
+
* Build assertion including Phase 3 attachment upload (FR58).
|
|
38
|
+
*/
|
|
39
|
+
export declare function scenarioToAssertionAsync(scenario: ConvertedScenario): Promise<CucumberAssertionInput | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Normalize Cucumber scenarios into FR41 jest-json shape A (FR50).
|
|
42
|
+
*/
|
|
43
|
+
export declare function toJestJsonReport(specs: readonly CucumberSpecInput[], startTime?: number): JestVitestJsonReport;
|
|
44
|
+
/** Group assertions by feature URI. */
|
|
45
|
+
export declare function specsFromAssertions(assertionsByUri: Map<string, CucumberAssertionInput[]>, runStart: number, runEnd: number): CucumberSpecInput[];
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadScenarioAttachments = uploadScenarioAttachments;
|
|
4
|
+
exports.scenarioToAssertion = scenarioToAssertion;
|
|
5
|
+
exports.scenarioToAssertionAsync = scenarioToAssertionAsync;
|
|
6
|
+
exports.toJestJsonReport = toJestJsonReport;
|
|
7
|
+
exports.specsFromAssertions = specsFromAssertions;
|
|
8
|
+
const forge_commons_1 = require("@qanalyzer/forge-commons");
|
|
9
|
+
const tag_parser_1 = require("./modules/tag-parser");
|
|
10
|
+
function mapStepStatus(status) {
|
|
11
|
+
if (status === 'FAILED' || status === 'AMBIGUOUS')
|
|
12
|
+
return 'failed';
|
|
13
|
+
if (status === 'PASSED')
|
|
14
|
+
return 'passed';
|
|
15
|
+
return 'skipped';
|
|
16
|
+
}
|
|
17
|
+
function decodeAttachmentBody(body, contentEncoding) {
|
|
18
|
+
const encoding = contentEncoding.toUpperCase();
|
|
19
|
+
if (encoding === 'BASE64') {
|
|
20
|
+
return Buffer.from(body, 'base64');
|
|
21
|
+
}
|
|
22
|
+
return Buffer.from(body, 'utf8');
|
|
23
|
+
}
|
|
24
|
+
function defaultFileName(att, index) {
|
|
25
|
+
if (att.fileName)
|
|
26
|
+
return att.fileName;
|
|
27
|
+
const subtype = att.mediaType.split('/')[1];
|
|
28
|
+
if (subtype && /^[a-z0-9.+-]+$/i.test(subtype)) {
|
|
29
|
+
return `attachment-${index + 1}.${subtype}`;
|
|
30
|
+
}
|
|
31
|
+
return `attachment-${index + 1}.bin`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Upload Cucumber attachments (FR58). Never throws — missing key / oversize /
|
|
35
|
+
* config → metadata-only wire entries.
|
|
36
|
+
*/
|
|
37
|
+
async function uploadScenarioAttachments(scenario, title, tagIssueKeys) {
|
|
38
|
+
const entries = [];
|
|
39
|
+
const issueKeySources = [
|
|
40
|
+
...tagIssueKeys,
|
|
41
|
+
title,
|
|
42
|
+
scenario.title,
|
|
43
|
+
scenario.pickle.name,
|
|
44
|
+
...(scenario.pickle.tags ?? []).map((t) => t.name),
|
|
45
|
+
];
|
|
46
|
+
for (let i = 0; i < scenario.attachments.length; i += 1) {
|
|
47
|
+
const att = scenario.attachments[i];
|
|
48
|
+
try {
|
|
49
|
+
const content = decodeAttachmentBody(att.body, att.contentEncoding);
|
|
50
|
+
const fileName = defaultFileName(att, i);
|
|
51
|
+
const outcome = await (0, forge_commons_1.uploadAttachmentForQa)({
|
|
52
|
+
fileName,
|
|
53
|
+
mimeType: att.mediaType,
|
|
54
|
+
content,
|
|
55
|
+
issueKey: tagIssueKeys[0],
|
|
56
|
+
issueKeySources,
|
|
57
|
+
});
|
|
58
|
+
entries.push({
|
|
59
|
+
type: 'qa-attach',
|
|
60
|
+
body: {
|
|
61
|
+
name: outcome.attachment.file_name ?? fileName,
|
|
62
|
+
contentType: outcome.attachment.mime_type ?? att.mediaType,
|
|
63
|
+
size: outcome.attachment.size,
|
|
64
|
+
content_ref: outcome.attachment.content_ref,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
entries.push({
|
|
70
|
+
type: 'qa-attach',
|
|
71
|
+
body: {
|
|
72
|
+
name: defaultFileName(att, i),
|
|
73
|
+
contentType: att.mediaType,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return entries;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Convert a finished Cucumber scenario into one FR41 assertion (or null if @QaIgnore).
|
|
82
|
+
* Pass pre-built attachEntries from {@link uploadScenarioAttachments} when available.
|
|
83
|
+
*/
|
|
84
|
+
function scenarioToAssertion(scenario, attachEntries = []) {
|
|
85
|
+
const tagMeta = (0, tag_parser_1.parseQaTags)(scenario.pickle.tags ?? []);
|
|
86
|
+
if (tagMeta.ignore)
|
|
87
|
+
return null;
|
|
88
|
+
const title = (0, tag_parser_1.resolveScenarioTitle)(scenario.title, tagMeta);
|
|
89
|
+
const ancestors = tagMeta.suite && tagMeta.suite.length > 0
|
|
90
|
+
? tagMeta.suite.split('\t').map((s) => s.trim()).filter(Boolean)
|
|
91
|
+
: [scenario.featureName];
|
|
92
|
+
const entries = [];
|
|
93
|
+
if (tagMeta.suite) {
|
|
94
|
+
entries.push({ type: 'qa-suite', body: tagMeta.suite });
|
|
95
|
+
}
|
|
96
|
+
if (Object.keys(tagMeta.fields).length > 0) {
|
|
97
|
+
entries.push({ type: 'qa-fields', body: tagMeta.fields });
|
|
98
|
+
}
|
|
99
|
+
if (Object.keys(tagMeta.parameters).length > 0) {
|
|
100
|
+
entries.push({ type: 'qa-parameters', body: tagMeta.parameters });
|
|
101
|
+
}
|
|
102
|
+
if (tagMeta.title) {
|
|
103
|
+
entries.push({ type: 'qa-title', body: tagMeta.title });
|
|
104
|
+
}
|
|
105
|
+
for (const step of scenario.steps) {
|
|
106
|
+
entries.push({ type: 'qa-step', body: step.text });
|
|
107
|
+
const stepStatus = mapStepStatus(step.status);
|
|
108
|
+
if (stepStatus === 'failed') {
|
|
109
|
+
entries.push({
|
|
110
|
+
type: 'qa-step-failed',
|
|
111
|
+
body: { name: step.text, status: 'failed' },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
entries.push({
|
|
116
|
+
type: 'qa-step-end',
|
|
117
|
+
body: { name: step.text, status: stepStatus },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
entries.push(...attachEntries);
|
|
122
|
+
const wire = (0, forge_commons_1.qaMetaFromEntries)(entries, {
|
|
123
|
+
framework: 'cucumberjs',
|
|
124
|
+
reporter: '@qanalyzer/forge-cucumberjs',
|
|
125
|
+
});
|
|
126
|
+
const assertion = {
|
|
127
|
+
ancestorTitles: ancestors,
|
|
128
|
+
title,
|
|
129
|
+
fullName: ancestors.length > 0 ? `${ancestors.join(' ')} ${title}` : title,
|
|
130
|
+
status: scenario.status,
|
|
131
|
+
duration: scenario.durationMs,
|
|
132
|
+
failureMessages: scenario.failureMessages,
|
|
133
|
+
};
|
|
134
|
+
if (wire) {
|
|
135
|
+
assertion.meta = { qa: wire };
|
|
136
|
+
}
|
|
137
|
+
return assertion;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Build assertion including Phase 3 attachment upload (FR58).
|
|
141
|
+
*/
|
|
142
|
+
async function scenarioToAssertionAsync(scenario) {
|
|
143
|
+
const tagMeta = (0, tag_parser_1.parseQaTags)(scenario.pickle.tags ?? []);
|
|
144
|
+
if (tagMeta.ignore)
|
|
145
|
+
return null;
|
|
146
|
+
const title = (0, tag_parser_1.resolveScenarioTitle)(scenario.title, tagMeta);
|
|
147
|
+
const attachEntries = await uploadScenarioAttachments(scenario, title, tagMeta.issueKeys);
|
|
148
|
+
return scenarioToAssertion(scenario, attachEntries);
|
|
149
|
+
}
|
|
150
|
+
function mapAssertion(a) {
|
|
151
|
+
const assertion = {
|
|
152
|
+
ancestorTitles: a.ancestorTitles,
|
|
153
|
+
fullName: a.fullName ??
|
|
154
|
+
(a.ancestorTitles.length > 0
|
|
155
|
+
? `${a.ancestorTitles.join(' ')} ${a.title}`
|
|
156
|
+
: a.title),
|
|
157
|
+
title: a.title,
|
|
158
|
+
status: a.status,
|
|
159
|
+
duration: a.duration,
|
|
160
|
+
failureMessages: a.failureMessages ?? [],
|
|
161
|
+
};
|
|
162
|
+
if (a.meta?.qa) {
|
|
163
|
+
assertion.meta = { qa: a.meta.qa };
|
|
164
|
+
}
|
|
165
|
+
return assertion;
|
|
166
|
+
}
|
|
167
|
+
function fileStatus(assertions) {
|
|
168
|
+
return assertions.some((a) => a.status === 'failed') ? 'failed' : 'passed';
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Normalize Cucumber scenarios into FR41 jest-json shape A (FR50).
|
|
172
|
+
*/
|
|
173
|
+
function toJestJsonReport(specs, startTime) {
|
|
174
|
+
const testResults = specs.map((spec) => {
|
|
175
|
+
const assertionResults = spec.assertions.map(mapAssertion);
|
|
176
|
+
return {
|
|
177
|
+
name: spec.name,
|
|
178
|
+
status: fileStatus(assertionResults),
|
|
179
|
+
startTime: spec.startTime,
|
|
180
|
+
endTime: spec.endTime,
|
|
181
|
+
assertionResults,
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
let numPassedTests = 0;
|
|
185
|
+
let numFailedTests = 0;
|
|
186
|
+
let numPendingTests = 0;
|
|
187
|
+
let numTodoTests = 0;
|
|
188
|
+
for (const file of testResults) {
|
|
189
|
+
for (const a of file.assertionResults ?? []) {
|
|
190
|
+
if (a.status === 'passed')
|
|
191
|
+
numPassedTests += 1;
|
|
192
|
+
else if (a.status === 'failed')
|
|
193
|
+
numFailedTests += 1;
|
|
194
|
+
else if (a.status === 'todo')
|
|
195
|
+
numTodoTests += 1;
|
|
196
|
+
else
|
|
197
|
+
numPendingTests += 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const numTotalTests = numPassedTests + numFailedTests + numPendingTests + numTodoTests;
|
|
201
|
+
const numFailedTestSuites = testResults.filter((t) => t.status === 'failed')
|
|
202
|
+
.length;
|
|
203
|
+
const numPassedTestSuites = testResults.length - numFailedTestSuites;
|
|
204
|
+
return {
|
|
205
|
+
numTotalTestSuites: testResults.length,
|
|
206
|
+
numPassedTestSuites,
|
|
207
|
+
numFailedTestSuites,
|
|
208
|
+
numPendingTestSuites: 0,
|
|
209
|
+
numTotalTests,
|
|
210
|
+
numPassedTests,
|
|
211
|
+
numFailedTests,
|
|
212
|
+
numPendingTests,
|
|
213
|
+
numTodoTests,
|
|
214
|
+
startTime,
|
|
215
|
+
success: numFailedTests === 0,
|
|
216
|
+
testResults,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** Group assertions by feature URI. */
|
|
220
|
+
function specsFromAssertions(assertionsByUri, runStart, runEnd) {
|
|
221
|
+
const specs = [];
|
|
222
|
+
for (const [name, assertions] of assertionsByUri) {
|
|
223
|
+
if (assertions.length === 0)
|
|
224
|
+
continue;
|
|
225
|
+
specs.push({
|
|
226
|
+
name,
|
|
227
|
+
startTime: runStart,
|
|
228
|
+
endTime: runEnd,
|
|
229
|
+
assertions,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return specs;
|
|
233
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qanalyzer/forge-cucumberjs",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "QAnalyzer CucumberJS formatter \u2014 ingest or file modes via @qanalyzer/forge-commons",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"qanalyzer",
|
|
7
|
+
"cucumber",
|
|
8
|
+
"cucumberjs",
|
|
9
|
+
"reporter",
|
|
10
|
+
"testing",
|
|
11
|
+
"jira"
|
|
12
|
+
],
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"!dist/__tests__",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "npm run clean && npx tsc --project tsconfig.build.json",
|
|
32
|
+
"clean": "rm -rf dist",
|
|
33
|
+
"test": "npm run build && node --test dist/__tests__/**/*.test.js",
|
|
34
|
+
"prepublishOnly": "npm test"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@cucumber/messages": "^34.1.0",
|
|
38
|
+
"@wdio/reporter": "9.29.1",
|
|
39
|
+
"mocha": "^11.3.0",
|
|
40
|
+
"@qanalyzer/forge-commons": "^1.1.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@cucumber/cucumber": ">=10.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@cucumber/cucumber": "^13.1.0"
|
|
47
|
+
},
|
|
48
|
+
"license": "Apache-2.0"
|
|
49
|
+
}
|