qagentic-reporter 0.1.37 → 0.1.39

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.
@@ -911,7 +911,6 @@ var QAgenticCypressReporter = class {
911
911
  end: /* @__PURE__ */ new Date(),
912
912
  duration: 0
913
913
  };
914
- this.failedTestResults = [];
915
914
  this.pendingTests = [];
916
915
  this.projectName = process.env.QAGENTIC_PROJECT_NAME || config.projectId || "Cypress E2E Tests";
917
916
  this.environment = process.env.QAGENTIC_ENVIRONMENT || process.env.NODE_ENV || "e2e";
@@ -997,85 +996,73 @@ var QAgenticCypressReporter = class {
997
996
  type: testResult.errorType,
998
997
  hasStackTrace: !!testResult.stackTrace
999
998
  });
1000
- this.failedTestResults.push({
1001
- testResult,
1002
- test
1003
- });
1004
999
  }
1005
1000
  this.stats.tests++;
1006
1001
  if (test.state === "passed") this.stats.passes++;
1007
1002
  if (test.state === "failed") this.stats.failures++;
1008
1003
  if (test.state === "pending") this.stats.pending++;
1009
- this.pendingTests.push(testResult);
1004
+ this.pendingTests.push({
1005
+ testResult,
1006
+ test
1007
+ });
1010
1008
  } catch (error) {
1011
1009
  console.warn("[QAagentic] Failed to report test:", error);
1012
1010
  }
1013
1011
  }
1014
1012
  async attachScreenshots() {
1015
1013
  console.log("[QAagentic] Attaching screenshots to pending tests, count:", this.pendingTests.length);
1016
- for (const testResult of this.pendingTests) {
1017
- const failedTest = this.failedTestResults.find((ft) => ft.testResult.id === testResult.id);
1018
- if (failedTest && failedTest.test.invocationDetails?.relativeFile) {
1019
- const test = failedTest.test;
1020
- const testFileName = test.invocationDetails.relativeFile.replace(/\.ts$/, "");
1021
- const testName = test.title[test.title.length - 1];
1022
- const fullTestTitle = test.title.join(", ");
1023
- const screenshotPaths = [
1024
- // Mochawesome report assets location with full title
1025
- path2.join(
1026
- process.cwd(),
1027
- "cypress/reports/assets",
1028
- testFileName,
1029
- `${fullTestTitle} -- ${testName} (failed).png`
1030
- ),
1031
- // Alternative: without full title path
1032
- path2.join(
1033
- process.cwd(),
1034
- "cypress/reports/assets",
1035
- testFileName,
1036
- `${testName} (failed).png`
1037
- ),
1038
- // Legacy cypress/screenshots location
1039
- path2.join(
1040
- process.cwd(),
1041
- "cypress/screenshots",
1042
- `${testFileName} -- ${testName} (failed).png`
1043
- )
1044
- ];
1045
- let screenshotFound = false;
1046
- for (const screenshotPath of screenshotPaths) {
1047
- console.log("[QAagentic] Looking for screenshot at:", screenshotPath);
1048
- if (fs2.existsSync(screenshotPath)) {
1049
- try {
1050
- const screenshotContent = fs2.readFileSync(screenshotPath);
1051
- const attachment = {
1052
- id: v4(),
1053
- name: "screenshot",
1054
- type: "image/png",
1055
- extension: "png",
1056
- content: screenshotContent.toString("base64"),
1057
- size: screenshotContent.length,
1058
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1059
- };
1060
- testResult.attachments.push(attachment);
1061
- console.log("[QAagentic] Added screenshot attachment:", screenshotPath);
1062
- screenshotFound = true;
1063
- break;
1064
- } catch (err) {
1065
- console.warn("[QAagentic] Failed to read screenshot:", err);
1066
- }
1014
+ for (const { testResult, test } of this.pendingTests) {
1015
+ if (test.state !== "failed" || !test.invocationDetails?.relativeFile) {
1016
+ continue;
1017
+ }
1018
+ const testFileName = test.invocationDetails.relativeFile.replace(/\.ts$/, "");
1019
+ const fullTestTitle = test.title.join(" -- ");
1020
+ const screenshotPaths = [
1021
+ // Mochawesome report assets location - most recent screenshot (no attempt number)
1022
+ path2.join(
1023
+ process.cwd(),
1024
+ "cypress/reports/assets",
1025
+ testFileName,
1026
+ `${fullTestTitle} (failed).png`
1027
+ ),
1028
+ // With attempt number (fallback)
1029
+ path2.join(
1030
+ process.cwd(),
1031
+ "cypress/reports/assets",
1032
+ testFileName,
1033
+ `${fullTestTitle} (failed) (attempt 1).png`
1034
+ )
1035
+ ];
1036
+ let screenshotFound = false;
1037
+ for (const screenshotPath of screenshotPaths) {
1038
+ if (fs2.existsSync(screenshotPath)) {
1039
+ try {
1040
+ const screenshotContent = fs2.readFileSync(screenshotPath);
1041
+ testResult.attachments.push({
1042
+ id: v4(),
1043
+ name: "screenshot",
1044
+ type: "image/png",
1045
+ extension: "png",
1046
+ content: screenshotContent.toString("base64"),
1047
+ size: screenshotContent.length,
1048
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
1049
+ });
1050
+ console.log("[QAagentic] Added screenshot for:", fullTestTitle);
1051
+ screenshotFound = true;
1052
+ break;
1053
+ } catch (err) {
1054
+ console.warn("[QAagentic] Failed to read screenshot:", err);
1067
1055
  }
1068
1056
  }
1069
- if (!screenshotFound) {
1070
- console.log("[QAagentic] No screenshots found for test:", testName);
1071
- }
1057
+ }
1058
+ if (!screenshotFound) {
1059
+ console.log("[QAagentic] No screenshot found for:", fullTestTitle);
1072
1060
  }
1073
1061
  }
1074
- this.failedTestResults = [];
1075
1062
  }
1076
1063
  async sendPendingTests() {
1077
1064
  console.log("[QAagentic] Sending", this.pendingTests.length, "pending tests to API");
1078
- for (const testResult of this.pendingTests) {
1065
+ for (const { testResult } of this.pendingTests) {
1079
1066
  await this.reporter.reportTest(testResult);
1080
1067
  }
1081
1068
  this.pendingTests = [];