qagentic-reporter 0.1.14 → 0.1.16

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.
@@ -428,18 +428,28 @@ var APIReporter = class {
428
428
  if (!this.config.api.enabled) return;
429
429
  await this.flushBatch();
430
430
  try {
431
- await axios.patch(
431
+ console.log("[APIReporter] Finalizing run with test counts:", {
432
+ total: run.total,
433
+ passed: run.passed,
434
+ failed: run.failed,
435
+ broken: run.broken,
436
+ skipped: run.skipped
437
+ });
438
+ const patchData = {
439
+ end_time: run.endTime?.toISOString(),
440
+ duration_ms: run.durationMs,
441
+ total: run.total,
442
+ passed: run.passed,
443
+ failed: run.failed,
444
+ broken: run.broken,
445
+ skipped: run.skipped,
446
+ status: "completed"
447
+ };
448
+ console.log("[APIReporter] PATCH to:", `${this.config.api.url}/api/v1/runs/${run.id}`);
449
+ console.log("[APIReporter] PATCH data:", patchData);
450
+ const response = await axios.patch(
432
451
  `${this.config.api.url}/api/v1/runs/${run.id}`,
433
- {
434
- end_time: run.endTime?.toISOString(),
435
- duration_ms: run.durationMs,
436
- total: run.total,
437
- passed: run.passed,
438
- failed: run.failed,
439
- broken: run.broken,
440
- skipped: run.skipped,
441
- status: "completed"
442
- },
452
+ patchData,
443
453
  {
444
454
  headers: {
445
455
  "Content-Type": "application/json",
@@ -448,8 +458,12 @@ var APIReporter = class {
448
458
  timeout: this.config.api.timeout
449
459
  }
450
460
  );
461
+ console.log("[APIReporter] Run finalized successfully:", response.status);
451
462
  } catch (error) {
452
- console.warn("Warning: Failed to finalize run with API:", error);
463
+ console.warn("[APIReporter] Failed to finalize run with API:");
464
+ console.warn(" Error:", error.message);
465
+ console.warn(" Status:", error.response?.status);
466
+ console.warn(" Data:", error.response?.data);
453
467
  }
454
468
  }
455
469
  async reportTest(test) {
@@ -851,94 +865,103 @@ function attachJson(data, name = "JSON Data") {
851
865
  function attachText(text, name = "Text") {
852
866
  return attach(text, name, "text/plain", "txt");
853
867
  }
854
- function setupQAgentic(on, config) {
855
- const projectName = process.env.QAGENTIC_PROJECT_NAME || config.projectId || "Cypress E2E Tests";
856
- const environment = process.env.QAGENTIC_ENVIRONMENT || process.env.NODE_ENV || "e2e";
857
- const apiUrl = process.env.QAGENTIC_API_URL || "http://localhost:8080";
858
- console.log("[QAagentic] Initializing with config:", { projectName, environment, apiUrl });
859
- configure({
860
- projectName,
861
- environment,
862
- apiUrl,
863
- outputDir: "./qagentic-results"
864
- });
865
- const reporter = QAgenticReporter.getInstance();
866
- let currentRun = null;
867
- console.log("[QAagentic] Reporter initialized, setting up hooks");
868
- (async () => {
868
+ var QAgenticCypressReporter = class {
869
+ constructor(config) {
870
+ this.currentRun = null;
871
+ this.stats = {
872
+ suites: 0,
873
+ tests: 0,
874
+ passes: 0,
875
+ pending: 0,
876
+ failures: 0,
877
+ start: /* @__PURE__ */ new Date(),
878
+ end: /* @__PURE__ */ new Date(),
879
+ duration: 0
880
+ };
881
+ this.projectName = process.env.QAGENTIC_PROJECT_NAME || config.projectId || "Cypress E2E Tests";
882
+ this.environment = process.env.QAGENTIC_ENVIRONMENT || process.env.NODE_ENV || "e2e";
883
+ const apiUrl = process.env.QAGENTIC_API_URL || "http://localhost:8080";
884
+ configure({
885
+ projectName: this.projectName,
886
+ environment: this.environment,
887
+ apiUrl,
888
+ outputDir: "./qagentic-results"
889
+ });
890
+ this.reporter = QAgenticReporter.getInstance();
891
+ this.stats.start = /* @__PURE__ */ new Date();
892
+ }
893
+ async onRunBegin() {
869
894
  try {
870
- console.log("[QAagentic] Starting test run immediately");
871
- currentRun = await reporter.startRun({
872
- name: `cypress_${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "")}`,
873
- projectName,
874
- environment
895
+ this.currentRun = await this.reporter.startRun({
896
+ name: this.projectName,
897
+ projectName: this.projectName,
898
+ environment: this.environment,
899
+ startTime: this.stats.start
875
900
  });
876
- console.log("[QAagentic] Test run started successfully:", currentRun?.id);
877
901
  } catch (error) {
878
902
  console.warn("[QAagentic] Failed to start run:", error);
879
903
  }
880
- })();
881
- on("after:spec", async (_spec, results) => {
904
+ }
905
+ async onTestEnd(test) {
906
+ if (!this.currentRun) return;
882
907
  try {
883
- console.log("[QAagentic] after:spec hook started for:", results.spec.relative);
884
- if (!results?.tests) {
885
- console.log("[QAagentic] No tests found in spec results");
886
- return;
887
- }
888
- for (const test of results.tests) {
889
- try {
890
- const testResult = {
891
- id: v4(),
892
- name: test.title[test.title.length - 1],
893
- fullName: test.title.join(" > "),
894
- status: parseStatus(test.state),
895
- durationMs: test.duration,
896
- startTime: new Date(Date.now() - test.duration),
897
- endTime: /* @__PURE__ */ new Date(),
898
- labels: {
899
- suite: test.title.slice(0, -1).join(" > "),
900
- feature: test.title[0]
901
- },
902
- links: [],
903
- parameters: {},
904
- steps: [],
905
- attachments: [],
906
- filePath: results.spec.relative,
907
- retryCount: 0,
908
- isRetry: false,
909
- isFlaky: false
910
- };
911
- if (test.err) {
912
- testResult.errorMessage = test.err.message;
913
- testResult.stackTrace = test.err.stack;
914
- testResult.errorType = "AssertionError";
915
- }
916
- console.log("[QAagentic] Reporting test:", testResult.name, "-", testResult.status);
917
- await reporter.reportTest(testResult);
918
- } catch (error) {
919
- console.warn("[QAagentic] Failed to report test:", error);
920
- }
908
+ const testResult = {
909
+ id: v4(),
910
+ name: test.title[test.title.length - 1],
911
+ fullName: test.title.join(" > "),
912
+ status: parseStatus(test.state),
913
+ durationMs: test.duration,
914
+ startTime: new Date(Date.now() - test.duration),
915
+ endTime: /* @__PURE__ */ new Date(),
916
+ labels: {
917
+ suite: test.title.slice(0, -1).join(" > "),
918
+ feature: test.title[0]
919
+ },
920
+ links: [],
921
+ parameters: {},
922
+ steps: [],
923
+ attachments: [],
924
+ filePath: test.invocationDetails?.relativeFile || "",
925
+ retryCount: 0,
926
+ isRetry: false,
927
+ isFlaky: false
928
+ };
929
+ if (test.err) {
930
+ testResult.errorMessage = test.err.message;
931
+ testResult.stackTrace = test.err.stack;
932
+ testResult.errorType = "AssertionError";
921
933
  }
922
- console.log("[QAagentic] after:spec hook completed");
934
+ this.stats.tests++;
935
+ if (test.state === "passed") this.stats.passes++;
936
+ if (test.state === "failed") this.stats.failures++;
937
+ if (test.state === "pending") this.stats.pending++;
938
+ await this.reporter.reportTest(testResult);
923
939
  } catch (error) {
924
- console.warn("[QAagentic] Error in after:spec hook:", error);
940
+ console.warn("[QAagentic] Failed to report test:", error);
925
941
  }
926
- });
927
- on("task", {
928
- qagentic_endRun: async () => {
929
- try {
930
- console.log("[QAagentic] Ending test run and flushing batch");
931
- await reporter.endRun();
932
- console.log("[QAagentic] Test run completed and results sent");
933
- await new Promise((resolve) => setTimeout(resolve, 2e3));
934
- console.log("[QAagentic] All operations completed");
935
- return null;
936
- } catch (error) {
937
- console.warn("[QAagentic] Failed to end run:", error);
938
- return null;
939
- }
942
+ }
943
+ async onRunEnd() {
944
+ if (!this.currentRun) return;
945
+ try {
946
+ this.stats.end = /* @__PURE__ */ new Date();
947
+ this.stats.duration = this.stats.end.getTime() - this.stats.start.getTime();
948
+ this.currentRun.endTime = this.stats.end;
949
+ this.currentRun.durationMs = this.stats.duration;
950
+ this.currentRun.total = this.stats.tests;
951
+ this.currentRun.passed = this.stats.passes;
952
+ this.currentRun.failed = this.stats.failures;
953
+ this.currentRun.skipped = this.stats.pending;
954
+ await this.reporter.endRun();
955
+ } catch (error) {
956
+ console.warn("[QAagentic] Failed to end run:", error);
940
957
  }
941
- });
958
+ }
959
+ };
960
+ function setupQAgentic(on, config) {
961
+ const reporter = new QAgenticCypressReporter(config);
962
+ on("before:run", () => reporter.onRunBegin());
963
+ on("test:after:run", (test) => reporter.onTestEnd(test));
964
+ on("after:run", () => reporter.onRunEnd());
942
965
  }
943
966
 
944
967
  // src/cypress/index.ts