@ai-testing-tool/forge-cypress 2.0.0

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 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,105 @@
1
+ # @ai-testing-tool/forge-cypress
2
+
3
+ Cypress reporter + plugin for **AI Testing Tool** (Jira Forge quality hub).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -D @ai-testing-tool/forge-cypress@2.0.0 @ai-testing-tool/forge-commons@2.0.0 cypress-multi-reporters
9
+ ```
10
+
11
+ The pinned versions above track the latest release; `npm run release:bump` keeps them in sync.
12
+
13
+ Peer: `cypress` ≥12, `mocha` ≥10 (Cypress ships Mocha).
14
+
15
+ ## Configure
16
+
17
+ ```js
18
+ // cypress.config.js
19
+ const { defineConfig } = require('cypress');
20
+
21
+ module.exports = defineConfig({
22
+ reporter: 'cypress-multi-reporters',
23
+ reporterOptions: {
24
+ reporterEnabled: '@ai-testing-tool/forge-cypress',
25
+ qaCypressReporterOptions: {
26
+ // Defaults to mode=off (no credentials required)
27
+ // mode: 'ingest' | 'file' | 'off',
28
+ // projectKey: 'DEMO',
29
+ // resultsPath: './.qa-cypress-results.json',
30
+ },
31
+ },
32
+ e2e: {
33
+ setupNodeEvents(on, config) {
34
+ require('@ai-testing-tool/forge-cypress/plugin')(on, config);
35
+ require('@ai-testing-tool/forge-cypress/metadata')(on);
36
+ return config;
37
+ },
38
+ },
39
+ });
40
+ ```
41
+
42
+ Direct reporter (no multi-reporters):
43
+
44
+ ```js
45
+ reporter: '@ai-testing-tool/forge-cypress',
46
+ ```
47
+
48
+ **Required:** register `@ai-testing-tool/forge-cypress/plugin` so `after:run` publishes one launch for the whole `cypress run` (results are buffered across specs).
49
+
50
+ ### Modes
51
+
52
+ | Mode | Behavior |
53
+ | ---- | -------- |
54
+ | `off` (default) | No network / file write |
55
+ | `file` | Writes the ingest payload (default `./ai-testing-tool-results.json`) |
56
+ | `ingest` | POSTs the payload with `format: jest-json` |
57
+
58
+ Env (same as CLI): `AI_TESTING_TOOL_MODE`, `AI_TESTING_TOOL_PROJECT_KEY`, `AI_TESTING_TOOL_INGEST_URL`, `AI_TESTING_TOOL_INGEST_TOKEN`, `AI_TESTING_TOOL_LAUNCH_NAME`.
59
+
60
+ Results bridge path: `resultsPath` reporter option or `AI_TESTING_TOOL_CYPRESS_RESULTS_PATH` env var (default: `<projectRoot>/.qa-cypress-results.json`).
61
+
62
+ ## Helpers
63
+
64
+ ```js
65
+ const { qa } = require('@ai-testing-tool/forge-cypress/mocha');
66
+
67
+ it('AUTH-101 login', () => {
68
+ qa.suite('Auth');
69
+ qa.step('open form', () => {
70
+ // synchronous callback only — no async/await
71
+ cy.visit('/login');
72
+ });
73
+ });
74
+ ```
75
+
76
+ All helpers: `qa.title(value)`, `qa.comment(value)`, `qa.suite(value)`, `qa.parameters({ key: value })`, `qa.ignore()`, `qa.step(name, syncFn)`. `qa.step()` throws if the callback returns a Promise — keep it synchronous and let Cypress commands queue as usual.
77
+
78
+ Prefer **Jira issue keys in test titles**. Requires `@ai-testing-tool/forge-cypress/metadata` so `cy.task` bridges metadata to the Node reporter. Step hierarchy lands on `assertionResults[].meta.qa.steps`.
79
+
80
+ ## Failure screenshots
81
+
82
+ With `@ai-testing-tool/forge-cypress/plugin` registered, the `after:screenshot` hook records Cypress failure screenshots automatically. On publish (`mode=ingest` or `file`), each failed assertion gets a matching still image (png/jpeg/webp — videos are skipped) uploaded to Forge and attached as `meta.qa.attachments`. Screenshots are matched to assertions by test title, falling back to spec order; each screenshot is used at most once. Upload errors never fail the Cypress run.
83
+
84
+ ## Dual path
85
+
86
+ **Path A — file + CLI:**
87
+
88
+ ```bash
89
+ AI_TESTING_TOOL_MODE=file \
90
+ AI_TESTING_TOOL_PROJECT_KEY=DEMO \
91
+ npx cypress run
92
+ npx @ai-testing-tool/forge-api-client --project DEMO --report ai-testing-tool-results.json
93
+ ```
94
+
95
+ (`mode=file` already writes a ready-to-ingest payload; CLI re-upload is optional if you prefer the upload workflow.)
96
+
97
+ **Path B — reporter ingest:**
98
+
99
+ ```bash
100
+ AI_TESTING_TOOL_MODE=ingest \
101
+ AI_TESTING_TOOL_PROJECT_KEY=DEMO \
102
+ AI_TESTING_TOOL_INGEST_URL=... \
103
+ AI_TESTING_TOOL_INGEST_TOKEN=... \
104
+ npx cypress run
105
+ ```
@@ -0,0 +1,6 @@
1
+ import type { CypressSpecInput } from './report-builder';
2
+ /**
3
+ * For each failed assertion, upload a matching still-image screenshot if available.
4
+ * Each screenshot is consumed at most once.
5
+ */
6
+ export declare function enrichSpecsWithFailureScreenshots(specs: CypressSpecInput[], screenshotsPath?: string): Promise<void>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enrichSpecsWithFailureScreenshots = enrichSpecsWithFailureScreenshots;
4
+ /**
5
+ * Enrich failed Cypress assertions with Forge-uploaded still-image screenshots (FR71).
6
+ * Never throws — skipped / failed uploads still allow the run to finish.
7
+ */
8
+ const forge_commons_1 = require("@ai-testing-tool/forge-commons");
9
+ const screenshots_manager_1 = require("./screenshots-manager");
10
+ function ensureQaMeta(assertion) {
11
+ if (!assertion.meta)
12
+ assertion.meta = {};
13
+ if (!assertion.meta.qa) {
14
+ assertion.meta.qa = {
15
+ framework: 'cypress',
16
+ host: { framework: 'cypress', reporter: '@ai-testing-tool/forge-cypress' },
17
+ };
18
+ }
19
+ return assertion.meta.qa;
20
+ }
21
+ function pushAttachment(assertion, attachment) {
22
+ const qa = ensureQaMeta(assertion);
23
+ if (!qa.attachments)
24
+ qa.attachments = [];
25
+ qa.attachments.push(attachment);
26
+ }
27
+ async function uploadShot(shot, assertion) {
28
+ try {
29
+ if (!(0, screenshots_manager_1.isStillImagePath)(shot.path))
30
+ return;
31
+ const fileName = shot.path.split(/[/\\]/).pop() ?? 'screenshot.png';
32
+ const mimeType = /\.jpe?g$/i.test(fileName)
33
+ ? 'image/jpeg'
34
+ : /\.webp$/i.test(fileName)
35
+ ? 'image/webp'
36
+ : 'image/png';
37
+ const outcome = await (0, forge_commons_1.uploadAttachmentForQa)({
38
+ path: shot.path,
39
+ fileName,
40
+ mimeType,
41
+ issueKeySources: [assertion.title, assertion.fullName],
42
+ });
43
+ pushAttachment(assertion, outcome.attachment);
44
+ }
45
+ catch {
46
+ // Never fail the Cypress run
47
+ }
48
+ }
49
+ /**
50
+ * For each failed assertion, upload a matching still-image screenshot if available.
51
+ * Each screenshot is consumed at most once.
52
+ */
53
+ async function enrichSpecsWithFailureScreenshots(specs, screenshotsPath) {
54
+ const shots = screenshots_manager_1.ScreenshotsManager.getAll(screenshots_manager_1.ScreenshotsManager.resolvePath(screenshotsPath)).filter((s) => s.testFailure !== false && (0, screenshots_manager_1.isStillImagePath)(s.path));
55
+ const used = new Set();
56
+ for (const spec of specs) {
57
+ for (const assertion of spec.assertions) {
58
+ if (assertion.status !== 'failed')
59
+ continue;
60
+ let idx = shots.findIndex((s, i) => !used.has(i) && (0, screenshots_manager_1.matchScreenshotToAssertion)(s, assertion, spec.name));
61
+ // Fallback: next unused failure screenshot for this spec (order-preserved)
62
+ if (idx < 0) {
63
+ idx = (0, screenshots_manager_1.nextUnusedSpecScreenshot)(shots, used, spec.name);
64
+ }
65
+ if (idx < 0)
66
+ continue;
67
+ used.add(idx);
68
+ await uploadShot(shots[idx], assertion);
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,2 @@
1
+ import { CypressQaReporter } from './reporter';
2
+ export = CypressQaReporter;
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const reporter_1 = require("./reporter");
3
+ module.exports = reporter_1.CypressQaReporter;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * In-memory metadata for the current Cypress/Mocha test.
3
+ * Full result wiring lands in Story 2.6.2; scaffold keeps registration safe.
4
+ */
5
+ export type QaMetaEntry = {
6
+ type: string;
7
+ body: unknown;
8
+ };
9
+ export declare const MetadataManager: {
10
+ clear(): void;
11
+ push(type: string, body: unknown): void;
12
+ getEntries(): QaMetaEntry[];
13
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * In-memory metadata for the current Cypress/Mocha test.
4
+ * Full result wiring lands in Story 2.6.2; scaffold keeps registration safe.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.MetadataManager = void 0;
8
+ const entries = [];
9
+ exports.MetadataManager = {
10
+ clear() {
11
+ entries.length = 0;
12
+ },
13
+ push(type, body) {
14
+ entries.push({ type, body });
15
+ },
16
+ getEntries() {
17
+ return [...entries];
18
+ },
19
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Cypress task bridge for `@ai-testing-tool/forge-cypress/mocha` helpers.
3
+ * Register in setupNodeEvents:
4
+ * require('@ai-testing-tool/forge-cypress/metadata')(on);
5
+ */
6
+ type TaskOn = {
7
+ (event: 'task', tasks: Record<string, (value?: unknown) => unknown>): void;
8
+ };
9
+ declare function metadata(on: TaskOn): void;
10
+ export = metadata;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ const metadata_manager_1 = require("./metadata-manager");
3
+ function metadata(on) {
4
+ on('task', {
5
+ qaTitle(value) {
6
+ metadata_manager_1.MetadataManager.push('qa-title', value);
7
+ return null;
8
+ },
9
+ qaSuite(value) {
10
+ metadata_manager_1.MetadataManager.push('qa-suite', value);
11
+ return null;
12
+ },
13
+ qaComment(value) {
14
+ metadata_manager_1.MetadataManager.push('qa-comment', value);
15
+ return null;
16
+ },
17
+ qaParameters(value) {
18
+ metadata_manager_1.MetadataManager.push('qa-parameters', value);
19
+ return null;
20
+ },
21
+ qaIssueKey(value) {
22
+ metadata_manager_1.MetadataManager.push('qa-issue-key', value);
23
+ return null;
24
+ },
25
+ qaIssueKeys(value) {
26
+ metadata_manager_1.MetadataManager.push('qa-issue-keys', value);
27
+ return null;
28
+ },
29
+ qaIgnore() {
30
+ metadata_manager_1.MetadataManager.push('qa-ignore', true);
31
+ return null;
32
+ },
33
+ qaStepStart(value) {
34
+ metadata_manager_1.MetadataManager.push('qa-step', value);
35
+ return null;
36
+ },
37
+ qaStepEnd(value) {
38
+ metadata_manager_1.MetadataManager.push('qa-step-end', value);
39
+ return null;
40
+ },
41
+ });
42
+ }
43
+ module.exports = metadata;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Programmatic helpers for Cypress Mocha specs (FR63–FR64).
3
+ * Prefer `qa.issueKey()` / `qa.issueKeys()` for FR43 (do not embed keys in titles).
4
+ *
5
+ * `qa.step()` accepts **synchronous** callbacks only (no async/await) —
6
+ * Cypress command-queue safe.
7
+ *
8
+ * In the browser, helpers forward via `cy.task` (requires `@ai-testing-tool/forge-cypress/metadata`).
9
+ * Outside Cypress (unit tests), they use an in-process buffer.
10
+ */
11
+ import { MetadataManager } from './metadata-manager';
12
+ type SyncStepFn = () => void;
13
+ export type QaHelpers = {
14
+ title(value: string): void;
15
+ comment(value: string): void;
16
+ suite(value: string): void;
17
+ parameters(values: Record<string, string>): void;
18
+ /** Explicit FR43 issue key (preferred over embedding in titles). */
19
+ issueKey(key: string): void;
20
+ /** Explicit FR43 issue keys (preferred over embedding in titles). */
21
+ issueKeys(keys: string[]): void;
22
+ ignore(): void;
23
+ /** Sync callback only (FR64). */
24
+ step(name: string, body: SyncStepFn): void;
25
+ };
26
+ export declare const qa: QaHelpers;
27
+ export { MetadataManager };
28
+ export type { QaMetaEntry } from './metadata-manager';
package/dist/mocha.js ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ /**
3
+ * Programmatic helpers for Cypress Mocha specs (FR63–FR64).
4
+ * Prefer `qa.issueKey()` / `qa.issueKeys()` for FR43 (do not embed keys in titles).
5
+ *
6
+ * `qa.step()` accepts **synchronous** callbacks only (no async/await) —
7
+ * Cypress command-queue safe.
8
+ *
9
+ * In the browser, helpers forward via `cy.task` (requires `@ai-testing-tool/forge-cypress/metadata`).
10
+ * Outside Cypress (unit tests), they use an in-process buffer.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.MetadataManager = exports.qa = void 0;
14
+ const metadata_manager_1 = require("./metadata-manager");
15
+ Object.defineProperty(exports, "MetadataManager", { enumerable: true, get: function () { return metadata_manager_1.MetadataManager; } });
16
+ function cyRef() {
17
+ const g = globalThis;
18
+ return g.cy;
19
+ }
20
+ function isThenable(value) {
21
+ return (value !== null &&
22
+ typeof value === 'object' &&
23
+ typeof value.then === 'function');
24
+ }
25
+ function pushLocal(type, body) {
26
+ metadata_manager_1.MetadataManager.push(type, body);
27
+ }
28
+ function pushTask(taskName, body) {
29
+ return cyRef().task(taskName, body);
30
+ }
31
+ exports.qa = {
32
+ title(value) {
33
+ const cy = cyRef();
34
+ if (cy) {
35
+ pushTask('qaTitle', value);
36
+ return;
37
+ }
38
+ pushLocal('qa-title', value);
39
+ },
40
+ comment(value) {
41
+ const cy = cyRef();
42
+ if (cy) {
43
+ pushTask('qaComment', value);
44
+ return;
45
+ }
46
+ pushLocal('qa-comment', value);
47
+ },
48
+ suite(value) {
49
+ const cy = cyRef();
50
+ if (cy) {
51
+ pushTask('qaSuite', value);
52
+ return;
53
+ }
54
+ pushLocal('qa-suite', value);
55
+ },
56
+ parameters(values) {
57
+ const cy = cyRef();
58
+ if (cy) {
59
+ pushTask('qaParameters', values);
60
+ return;
61
+ }
62
+ pushLocal('qa-parameters', values);
63
+ },
64
+ issueKey(key) {
65
+ const cy = cyRef();
66
+ if (cy) {
67
+ pushTask('qaIssueKey', key);
68
+ return;
69
+ }
70
+ pushLocal('qa-issue-key', key);
71
+ },
72
+ issueKeys(keys) {
73
+ const cy = cyRef();
74
+ if (cy) {
75
+ pushTask('qaIssueKeys', keys);
76
+ return;
77
+ }
78
+ pushLocal('qa-issue-keys', keys);
79
+ },
80
+ ignore() {
81
+ const cy = cyRef();
82
+ if (cy) {
83
+ pushTask('qaIgnore');
84
+ return;
85
+ }
86
+ pushLocal('qa-ignore', true);
87
+ },
88
+ step(name, body) {
89
+ const cy = cyRef();
90
+ if (cy) {
91
+ pushTask('qaStepStart', name)
92
+ .then(() => {
93
+ const result = body();
94
+ if (isThenable(result)) {
95
+ throw new Error('qa.step() requires a synchronous callback (no async/await) — FR64');
96
+ }
97
+ })
98
+ .then(() => {
99
+ pushTask('qaStepEnd', { name, status: 'passed' });
100
+ });
101
+ return;
102
+ }
103
+ pushLocal('qa-step', name);
104
+ try {
105
+ const result = body();
106
+ if (isThenable(result)) {
107
+ throw new Error('qa.step() requires a synchronous callback (no async/await) — FR64');
108
+ }
109
+ pushLocal('qa-step-end', { name, status: 'passed' });
110
+ }
111
+ catch (error) {
112
+ pushLocal('qa-step-failed', { name, status: 'failed' });
113
+ throw error;
114
+ }
115
+ },
116
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Cypress Node plugin — register in cypress.config.js setupNodeEvents:
3
+ * require('@ai-testing-tool/forge-cypress/plugin')(on, config);
4
+ *
5
+ * before:run clears the results bridge; after:run publishes FR41
6
+ * (mode=ingest | file) via @ai-testing-tool/forge-commons.
7
+ * after:screenshot captures failure still images for Phase 3 upload (FR71).
8
+ */
9
+ type PluginOn = {
10
+ (event: string, handler: (...args: unknown[]) => unknown): void;
11
+ };
12
+ type PluginConfig = Record<string, unknown> & {
13
+ projectRoot?: string;
14
+ reporterOptions?: Record<string, unknown> | null;
15
+ };
16
+ declare function plugin(on: PluginOn, config: PluginConfig): PluginConfig;
17
+ export = plugin;
package/dist/plugin.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /**
3
+ * Cypress Node plugin — register in cypress.config.js setupNodeEvents:
4
+ * require('@ai-testing-tool/forge-cypress/plugin')(on, config);
5
+ *
6
+ * before:run clears the results bridge; after:run publishes FR41
7
+ * (mode=ingest | file) via @ai-testing-tool/forge-commons.
8
+ * after:screenshot captures failure still images for Phase 3 upload (FR71).
9
+ */
10
+ const forge_commons_1 = require("@ai-testing-tool/forge-commons");
11
+ const enrich_screenshots_1 = require("./enrich-screenshots");
12
+ const report_builder_1 = require("./report-builder");
13
+ const resolve_options_1 = require("./resolve-options");
14
+ const results_manager_1 = require("./results-manager");
15
+ const screenshots_manager_1 = require("./screenshots-manager");
16
+ async function publishCollected(options) {
17
+ const path = results_manager_1.ResultsManager.resolvePath(options.resultsPath);
18
+ const specs = results_manager_1.ResultsManager.getSpecs(path);
19
+ if (specs.length === 0) {
20
+ screenshots_manager_1.ScreenshotsManager.clear();
21
+ return;
22
+ }
23
+ forge_commons_1.AiTestingToolReporter.resetInstance();
24
+ const reporter = forge_commons_1.AiTestingToolReporter.getInstance({
25
+ ...options,
26
+ mode: options.mode ?? forge_commons_1.ModeEnum.off,
27
+ });
28
+ const mode = reporter.getConfig().mode ?? forge_commons_1.ModeEnum.off;
29
+ if (mode === forge_commons_1.ModeEnum.off) {
30
+ results_manager_1.ResultsManager.clear(path);
31
+ screenshots_manager_1.ScreenshotsManager.clear();
32
+ return;
33
+ }
34
+ try {
35
+ await (0, enrich_screenshots_1.enrichSpecsWithFailureScreenshots)(specs);
36
+ }
37
+ catch {
38
+ // Never fail the Cypress run because of attach errors
39
+ }
40
+ const report = (0, report_builder_1.toJestJsonReport)(specs, Date.now());
41
+ await reporter.publishReport(report, {
42
+ format: 'jest-json',
43
+ launchName: options.launchName,
44
+ projectKey: options.projectKey,
45
+ });
46
+ results_manager_1.ResultsManager.clear(path);
47
+ screenshots_manager_1.ScreenshotsManager.clear();
48
+ }
49
+ function plugin(on, config) {
50
+ const qaOptions = (0, resolve_options_1.resolveQaOptions)(config.reporterOptions);
51
+ if (qaOptions.resultsPath) {
52
+ process.env.AI_TESTING_TOOL_CYPRESS_RESULTS_PATH = qaOptions.resultsPath;
53
+ }
54
+ else if (config.projectRoot && !process.env.AI_TESTING_TOOL_CYPRESS_RESULTS_PATH) {
55
+ process.env.AI_TESTING_TOOL_CYPRESS_RESULTS_PATH = `${config.projectRoot}/.qa-cypress-results.json`;
56
+ }
57
+ on('before:run', () => {
58
+ results_manager_1.ResultsManager.clear(results_manager_1.ResultsManager.resolvePath(qaOptions.resultsPath));
59
+ screenshots_manager_1.ScreenshotsManager.clear();
60
+ });
61
+ on('after:screenshot', (details) => {
62
+ try {
63
+ const d = details;
64
+ if (!d?.path)
65
+ return details;
66
+ screenshots_manager_1.ScreenshotsManager.append({
67
+ path: d.path,
68
+ name: d.name,
69
+ specName: d.specName,
70
+ testFailure: d.testFailure,
71
+ takenAt: d.takenAt,
72
+ });
73
+ }
74
+ catch {
75
+ // Never fail the Cypress run
76
+ }
77
+ return details;
78
+ });
79
+ on('after:run', async () => {
80
+ try {
81
+ await publishCollected((0, resolve_options_1.resolveQaOptions)(config.reporterOptions));
82
+ }
83
+ catch {
84
+ // Never fail the Cypress run because of publish errors
85
+ }
86
+ });
87
+ return config;
88
+ }
89
+ module.exports = plugin;
@@ -0,0 +1,23 @@
1
+ import type { JestVitestJsonReport, QaMetaWire } from '@ai-testing-tool/forge-commons';
2
+ export type CypressAssertionInput = {
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 CypressSpecInput = {
14
+ /** Spec path (e.g. cypress/e2e/login.cy.js) */
15
+ name: string;
16
+ startTime?: number;
17
+ endTime?: number;
18
+ assertions: CypressAssertionInput[];
19
+ };
20
+ /**
21
+ * Normalize collected Cypress/Mocha specs into FR41 jest-json shape A.
22
+ */
23
+ export declare function toJestJsonReport(specs: readonly CypressSpecInput[], startTime?: number): JestVitestJsonReport;
@@ -0,0 +1,72 @@
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
+ // Suite hierarchy lives in meta.qa.suite; omit ancestorTitles from FR41.
10
+ const assertion = {
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 Cypress/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').length;
57
+ const numPassedTestSuites = testResults.length - numFailedTestSuites;
58
+ return {
59
+ numTotalTestSuites: testResults.length,
60
+ numPassedTestSuites,
61
+ numFailedTestSuites,
62
+ numPendingTestSuites: 0,
63
+ numTotalTests,
64
+ numPassedTests,
65
+ numFailedTests,
66
+ numPendingTests,
67
+ numTodoTests,
68
+ startTime,
69
+ success: numFailedTests === 0,
70
+ testResults,
71
+ };
72
+ }
@@ -0,0 +1,24 @@
1
+ import { reporters, Runner, type MochaOptions } from 'mocha';
2
+ import { type OptionsType } from '@ai-testing-tool/forge-commons';
3
+ export type CypressQaOptions = OptionsType & {
4
+ /** Override results bridge path (also AI_TESTING_TOOL_CYPRESS_RESULTS_PATH). */
5
+ resultsPath?: string;
6
+ };
7
+ export type CypressQaReporterOptions = Omit<MochaOptions, 'reporterOptions'> & {
8
+ reporterOptions?: CypressQaOptions;
9
+ };
10
+ /**
11
+ * Cypress Mocha reporter for AiTestingTool.
12
+ *
13
+ * Collects per-`it()` results + `qa.*` metadata, appends to ResultsManager.
14
+ * Plugin `after:run` publishes FR41 (mode=ingest|file). mode=off no-ops.
15
+ */
16
+ export declare class CypressQaReporter extends reporters.Base {
17
+ private readonly options;
18
+ private readonly byFile;
19
+ private readonly runStart;
20
+ constructor(runner: Runner, options?: CypressQaReporterOptions);
21
+ private record;
22
+ private flushToResultsManager;
23
+ }
24
+ export default CypressQaReporter;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CypressQaReporter = void 0;
4
+ const mocha_1 = require("mocha");
5
+ const forge_commons_1 = require("@ai-testing-tool/forge-commons");
6
+ const metadata_manager_1 = require("./metadata-manager");
7
+ const results_manager_1 = require("./results-manager");
8
+ function mapStatus(state) {
9
+ if (state === 'failed')
10
+ return 'failed';
11
+ if (state === 'pending')
12
+ return 'pending';
13
+ return 'passed';
14
+ }
15
+ function ancestorTitles(test) {
16
+ try {
17
+ const path = typeof test.titlePath === 'function' ? test.titlePath() : [];
18
+ if (path.length > 1)
19
+ return path.slice(0, -1);
20
+ }
21
+ catch {
22
+ // fall through
23
+ }
24
+ const titles = [];
25
+ let parent = test.parent;
26
+ while (parent && !parent.root) {
27
+ if (parent.title)
28
+ titles.unshift(parent.title);
29
+ parent = parent.parent;
30
+ }
31
+ return titles;
32
+ }
33
+ function specFileName(test) {
34
+ const fromTest = test.file;
35
+ if (fromTest)
36
+ return fromTest;
37
+ let parent = test.parent;
38
+ while (parent) {
39
+ const file = parent.file;
40
+ if (file)
41
+ return file;
42
+ parent = parent.parent;
43
+ }
44
+ return 'unknown';
45
+ }
46
+ function failureMessages(test) {
47
+ const err = test.err;
48
+ if (!err)
49
+ return [];
50
+ const msg = err.stack || err.message;
51
+ return msg ? [msg] : [];
52
+ }
53
+ /**
54
+ * Cypress Mocha reporter for AiTestingTool.
55
+ *
56
+ * Collects per-`it()` results + `qa.*` metadata, appends to ResultsManager.
57
+ * Plugin `after:run` publishes FR41 (mode=ingest|file). mode=off no-ops.
58
+ */
59
+ class CypressQaReporter extends mocha_1.reporters.Base {
60
+ options;
61
+ byFile = new Map();
62
+ runStart = Date.now();
63
+ constructor(runner, options = {}) {
64
+ super(runner, options);
65
+ this.options = options.reporterOptions ?? {};
66
+ if (this.options.resultsPath) {
67
+ process.env.AI_TESTING_TOOL_CYPRESS_RESULTS_PATH = this.options.resultsPath;
68
+ }
69
+ runner.on(mocha_1.Runner.constants.EVENT_TEST_BEGIN, () => {
70
+ metadata_manager_1.MetadataManager.clear();
71
+ });
72
+ runner.on(mocha_1.Runner.constants.EVENT_TEST_PASS, (test) => {
73
+ this.record(test, 'passed');
74
+ });
75
+ runner.on(mocha_1.Runner.constants.EVENT_TEST_FAIL, (test) => {
76
+ this.record(test, 'failed');
77
+ });
78
+ runner.on(mocha_1.Runner.constants.EVENT_TEST_PENDING, (test) => {
79
+ this.record(test, 'pending');
80
+ });
81
+ runner.once(mocha_1.Runner.constants.EVENT_RUN_END, () => {
82
+ this.flushToResultsManager();
83
+ });
84
+ }
85
+ record(test, state) {
86
+ try {
87
+ const entries = metadata_manager_1.MetadataManager.getEntries();
88
+ const wire = (0, forge_commons_1.qaMetaFromEntries)(entries, {
89
+ framework: 'cypress',
90
+ reporter: '@ai-testing-tool/forge-cypress',
91
+ });
92
+ metadata_manager_1.MetadataManager.clear();
93
+ const ancestors = ancestorTitles(test);
94
+ const assertion = {
95
+ ancestorTitles: ancestors,
96
+ title: test.title,
97
+ fullName: ancestors.length > 0 ? `${ancestors.join(' ')} ${test.title}` : test.title,
98
+ status: mapStatus(state ?? test.state),
99
+ duration: test.duration ?? undefined,
100
+ failureMessages: state === 'failed' ? failureMessages(test) : [],
101
+ };
102
+ if (wire) {
103
+ assertion.meta = { qa: wire };
104
+ }
105
+ const file = specFileName(test);
106
+ const list = this.byFile.get(file) ?? [];
107
+ list.push(assertion);
108
+ this.byFile.set(file, list);
109
+ }
110
+ catch {
111
+ // Never fail the Cypress run
112
+ }
113
+ }
114
+ flushToResultsManager() {
115
+ try {
116
+ const mode = this.options.mode ?? forge_commons_1.ModeEnum.off;
117
+ // Always buffer when not off so after:run can publish; also buffer when
118
+ // off so local debugging of the bridge still works without publish.
119
+ const path = results_manager_1.ResultsManager.resolvePath(this.options.resultsPath);
120
+ for (const [name, assertions] of this.byFile) {
121
+ if (assertions.length === 0)
122
+ continue;
123
+ const spec = {
124
+ name,
125
+ startTime: this.runStart,
126
+ endTime: Date.now(),
127
+ assertions,
128
+ };
129
+ results_manager_1.ResultsManager.appendSpec(spec, path);
130
+ }
131
+ this.byFile.clear();
132
+ // Hint for logs / tests — actual publish is plugin after:run
133
+ void mode;
134
+ }
135
+ catch {
136
+ // Never fail the Cypress run
137
+ }
138
+ }
139
+ }
140
+ exports.CypressQaReporter = CypressQaReporter;
141
+ exports.default = CypressQaReporter;
@@ -0,0 +1,8 @@
1
+ import type { OptionsType } from '@ai-testing-tool/forge-commons';
2
+ /**
3
+ * Resolve @ai-testing-tool/forge-cypress options from Cypress reporterOptions.
4
+ * Supports cypress-multi-reporters wrapper and direct reporter config.
5
+ */
6
+ export declare function resolveQaOptions(reporterOptions: unknown): OptionsType & {
7
+ resultsPath?: string;
8
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveQaOptions = resolveQaOptions;
4
+ /**
5
+ * Resolve @ai-testing-tool/forge-cypress options from Cypress reporterOptions.
6
+ * Supports cypress-multi-reporters wrapper and direct reporter config.
7
+ */
8
+ function resolveQaOptions(reporterOptions) {
9
+ if (reporterOptions == null || typeof reporterOptions !== 'object') {
10
+ return {};
11
+ }
12
+ const record = reporterOptions;
13
+ const wrapped = record.qaCypressReporterOptions;
14
+ if (wrapped !== undefined && typeof wrapped === 'object' && wrapped !== null) {
15
+ return wrapped;
16
+ }
17
+ return record;
18
+ }
@@ -0,0 +1,11 @@
1
+ import type { CypressSpecInput } from './report-builder';
2
+ /**
3
+ * File bridge across Cypress specs (reporter may run once per spec).
4
+ * Plugin `before:run` clears; reporter appends; `after:run` reads + publishes.
5
+ */
6
+ export declare class ResultsManager {
7
+ static resolvePath(explicit?: string): string;
8
+ static clear(path?: string): void;
9
+ static getSpecs(path?: string): CypressSpecInput[];
10
+ static appendSpec(spec: CypressSpecInput, path?: string): void;
11
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResultsManager = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const node_os_1 = require("node:os");
7
+ const DEFAULT_BASENAME = 'qa-cypress-results.json';
8
+ /**
9
+ * File bridge across Cypress specs (reporter may run once per spec).
10
+ * Plugin `before:run` clears; reporter appends; `after:run` reads + publishes.
11
+ */
12
+ class ResultsManager {
13
+ static resolvePath(explicit) {
14
+ if (explicit)
15
+ return explicit;
16
+ if (process.env.AI_TESTING_TOOL_CYPRESS_RESULTS_PATH) {
17
+ return process.env.AI_TESTING_TOOL_CYPRESS_RESULTS_PATH;
18
+ }
19
+ return (0, node_path_1.join)((0, node_os_1.tmpdir)(), DEFAULT_BASENAME);
20
+ }
21
+ static clear(path = ResultsManager.resolvePath()) {
22
+ if ((0, node_fs_1.existsSync)(path)) {
23
+ try {
24
+ (0, node_fs_1.unlinkSync)(path);
25
+ }
26
+ catch {
27
+ // ignore
28
+ }
29
+ }
30
+ }
31
+ static getSpecs(path = ResultsManager.resolvePath()) {
32
+ if (!(0, node_fs_1.existsSync)(path))
33
+ return [];
34
+ try {
35
+ const raw = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf8'));
36
+ return Array.isArray(raw.specs) ? raw.specs : [];
37
+ }
38
+ catch {
39
+ return [];
40
+ }
41
+ }
42
+ static appendSpec(spec, path = ResultsManager.resolvePath()) {
43
+ const specs = ResultsManager.getSpecs(path);
44
+ const existing = specs.findIndex((s) => s.name === spec.name);
45
+ if (existing >= 0) {
46
+ specs[existing] = {
47
+ ...spec,
48
+ assertions: [
49
+ ...(specs[existing]?.assertions ?? []),
50
+ ...spec.assertions,
51
+ ],
52
+ };
53
+ }
54
+ else {
55
+ specs.push(spec);
56
+ }
57
+ try {
58
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(path), { recursive: true });
59
+ (0, node_fs_1.writeFileSync)(path, JSON.stringify({ specs }, null, 0), 'utf8');
60
+ }
61
+ catch {
62
+ // Never fail the Cypress run
63
+ }
64
+ }
65
+ }
66
+ exports.ResultsManager = ResultsManager;
@@ -0,0 +1,25 @@
1
+ export type CypressScreenshotRecord = {
2
+ path: string;
3
+ name?: string;
4
+ specName?: string;
5
+ testFailure?: boolean;
6
+ takenAt?: string;
7
+ };
8
+ export declare class ScreenshotsManager {
9
+ static resolvePath(explicit?: string): string;
10
+ static clear(path?: string): void;
11
+ static getAll(path?: string): CypressScreenshotRecord[];
12
+ static append(record: CypressScreenshotRecord, path?: string): void;
13
+ }
14
+ /** True for still images; videos are skipped (Phase 3 still-image only). */
15
+ export declare function isStillImagePath(filePath: string): boolean;
16
+ /**
17
+ * Match a failure screenshot to a failed assertion by title / fullName.
18
+ */
19
+ export declare function matchScreenshotToAssertion(shot: CypressScreenshotRecord, assertion: {
20
+ title: string;
21
+ fullName?: string;
22
+ status: string;
23
+ }, specName: string): boolean;
24
+ /** Next unused failure still-image for this spec (ordered fallback). */
25
+ export declare function nextUnusedSpecScreenshot(shots: readonly CypressScreenshotRecord[], used: ReadonlySet<number>, specName: string): number;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScreenshotsManager = void 0;
4
+ exports.isStillImagePath = isStillImagePath;
5
+ exports.matchScreenshotToAssertion = matchScreenshotToAssertion;
6
+ exports.nextUnusedSpecScreenshot = nextUnusedSpecScreenshot;
7
+ /**
8
+ * Bridge for Cypress `after:screenshot` details → plugin `after:run` upload (FR71).
9
+ */
10
+ const node_fs_1 = require("node:fs");
11
+ const node_path_1 = require("node:path");
12
+ const node_os_1 = require("node:os");
13
+ const DEFAULT_BASENAME = 'qa-cypress-screenshots.json';
14
+ function defaultPath() {
15
+ if (process.env.AI_TESTING_TOOL_CYPRESS_SCREENSHOTS_PATH) {
16
+ return process.env.AI_TESTING_TOOL_CYPRESS_SCREENSHOTS_PATH;
17
+ }
18
+ const results = process.env.AI_TESTING_TOOL_CYPRESS_RESULTS_PATH;
19
+ if (results) {
20
+ return results.replace(/\.json$/i, '') + '-screenshots.json';
21
+ }
22
+ return (0, node_path_1.join)((0, node_os_1.tmpdir)(), DEFAULT_BASENAME);
23
+ }
24
+ class ScreenshotsManager {
25
+ static resolvePath(explicit) {
26
+ return explicit ?? defaultPath();
27
+ }
28
+ static clear(path = ScreenshotsManager.resolvePath()) {
29
+ if ((0, node_fs_1.existsSync)(path)) {
30
+ try {
31
+ (0, node_fs_1.unlinkSync)(path);
32
+ }
33
+ catch {
34
+ // ignore
35
+ }
36
+ }
37
+ }
38
+ static getAll(path = ScreenshotsManager.resolvePath()) {
39
+ if (!(0, node_fs_1.existsSync)(path))
40
+ return [];
41
+ try {
42
+ const raw = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf8'));
43
+ return Array.isArray(raw.screenshots) ? raw.screenshots : [];
44
+ }
45
+ catch {
46
+ return [];
47
+ }
48
+ }
49
+ static append(record, path = ScreenshotsManager.resolvePath()) {
50
+ if (!record.path)
51
+ return;
52
+ const screenshots = ScreenshotsManager.getAll(path);
53
+ screenshots.push(record);
54
+ try {
55
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(path), { recursive: true });
56
+ (0, node_fs_1.writeFileSync)(path, JSON.stringify({ screenshots }, null, 0), 'utf8');
57
+ }
58
+ catch {
59
+ // Never fail the Cypress run
60
+ }
61
+ }
62
+ }
63
+ exports.ScreenshotsManager = ScreenshotsManager;
64
+ /** True for still images; videos are skipped (Phase 3 still-image only). */
65
+ function isStillImagePath(filePath) {
66
+ return /\.(png|jpe?g|webp|bmp)$/i.test(filePath);
67
+ }
68
+ function belongsToSpec(shot, specName) {
69
+ if (!shot.specName) {
70
+ // Path often contains the relative spec path
71
+ const hay = shot.path.replace(/\\/g, '/').toLowerCase();
72
+ const want = specName.replace(/\\/g, '/').toLowerCase();
73
+ const base = want.split('/').pop() ?? want;
74
+ return Boolean(base && hay.includes(base));
75
+ }
76
+ const normSpec = shot.specName.replace(/\\/g, '/').toLowerCase();
77
+ const normName = specName.replace(/\\/g, '/').toLowerCase();
78
+ return (normName.endsWith(normSpec) ||
79
+ normSpec.endsWith(normName) ||
80
+ normName.includes(normSpec) ||
81
+ normSpec.includes(normName.split('/').pop() ?? ''));
82
+ }
83
+ /**
84
+ * Match a failure screenshot to a failed assertion by title / fullName.
85
+ */
86
+ function matchScreenshotToAssertion(shot, assertion, specName) {
87
+ if (assertion.status !== 'failed')
88
+ return false;
89
+ if (shot.testFailure === false)
90
+ return false;
91
+ if (!isStillImagePath(shot.path))
92
+ return false;
93
+ if (!belongsToSpec(shot, specName))
94
+ return false;
95
+ const haystack = `${shot.path} ${shot.name ?? ''}`.toLowerCase();
96
+ const title = assertion.title.toLowerCase();
97
+ if (title && haystack.includes(title))
98
+ return true;
99
+ const full = (assertion.fullName ?? '').toLowerCase();
100
+ if (full && haystack.includes(full))
101
+ return true;
102
+ return false;
103
+ }
104
+ /** Next unused failure still-image for this spec (ordered fallback). */
105
+ function nextUnusedSpecScreenshot(shots, used, specName) {
106
+ return shots.findIndex((s, i) => !used.has(i) &&
107
+ s.testFailure !== false &&
108
+ isStillImagePath(s.path) &&
109
+ belongsToSpec(s, specName));
110
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@ai-testing-tool/forge-cypress",
3
+ "version": "2.0.0",
4
+ "description": "AI Testing Tool Cypress reporter + plugin — ingest or file modes via @ai-testing-tool/forge-commons",
5
+ "keywords": [
6
+ "ai-testing-tool",
7
+ "cypress",
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
+ "./plugin": {
24
+ "types": "./dist/plugin.d.ts",
25
+ "default": "./dist/plugin.js"
26
+ },
27
+ "./metadata": {
28
+ "types": "./dist/metadata.d.ts",
29
+ "default": "./dist/metadata.js"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "!dist/__tests__",
36
+ "README.md"
37
+ ],
38
+ "engines": {
39
+ "node": ">=18"
40
+ },
41
+ "scripts": {
42
+ "build": "npm run clean && npx tsc --project tsconfig.build.json && cp -R src/__fixtures__ dist/__fixtures__",
43
+ "clean": "rm -rf dist",
44
+ "test": "vitest run --config ../examples/single/vitest/vitest.config.ts --project qa-cypress",
45
+ "prepublishOnly": "npm test"
46
+ },
47
+ "dependencies": {
48
+ "@ai-testing-tool/forge-commons": "^2.0.0"
49
+ },
50
+ "peerDependencies": {
51
+ "cypress": ">=12.0.0",
52
+ "mocha": ">=10.0.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "mocha": {
56
+ "optional": false
57
+ }
58
+ },
59
+ "devDependencies": {
60
+ "@types/mocha": "^10.0.10",
61
+ "mocha": "^11.3.0"
62
+ },
63
+ "license": "Apache-2.0"
64
+ }