qagentic-reporter 0.1.15 → 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.
@@ -865,94 +865,103 @@ function attachJson(data, name = "JSON Data") {
865
865
  function attachText(text, name = "Text") {
866
866
  return attach(text, name, "text/plain", "txt");
867
867
  }
868
- function setupQAgentic(on, config) {
869
- const projectName = process.env.QAGENTIC_PROJECT_NAME || config.projectId || "Cypress E2E Tests";
870
- const environment = process.env.QAGENTIC_ENVIRONMENT || process.env.NODE_ENV || "e2e";
871
- const apiUrl = process.env.QAGENTIC_API_URL || "http://localhost:8080";
872
- console.log("[QAagentic] Initializing with config:", { projectName, environment, apiUrl });
873
- configure({
874
- projectName,
875
- environment,
876
- apiUrl,
877
- outputDir: "./qagentic-results"
878
- });
879
- const reporter = QAgenticReporter.getInstance();
880
- let currentRun = null;
881
- console.log("[QAagentic] Reporter initialized, setting up hooks");
882
- (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() {
883
894
  try {
884
- console.log("[QAagentic] Starting test run immediately");
885
- currentRun = await reporter.startRun({
886
- name: `cypress_${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "")}`,
887
- projectName,
888
- 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
889
900
  });
890
- console.log("[QAagentic] Test run started successfully:", currentRun?.id);
891
901
  } catch (error) {
892
902
  console.warn("[QAagentic] Failed to start run:", error);
893
903
  }
894
- })();
895
- on("after:spec", async (_spec, results) => {
904
+ }
905
+ async onTestEnd(test) {
906
+ if (!this.currentRun) return;
896
907
  try {
897
- console.log("[QAagentic] after:spec hook started for:", results.spec.relative);
898
- if (!results?.tests) {
899
- console.log("[QAagentic] No tests found in spec results");
900
- return;
901
- }
902
- for (const test of results.tests) {
903
- try {
904
- const testResult = {
905
- id: v4(),
906
- name: test.title[test.title.length - 1],
907
- fullName: test.title.join(" > "),
908
- status: parseStatus(test.state),
909
- durationMs: test.duration,
910
- startTime: new Date(Date.now() - test.duration),
911
- endTime: /* @__PURE__ */ new Date(),
912
- labels: {
913
- suite: test.title.slice(0, -1).join(" > "),
914
- feature: test.title[0]
915
- },
916
- links: [],
917
- parameters: {},
918
- steps: [],
919
- attachments: [],
920
- filePath: results.spec.relative,
921
- retryCount: 0,
922
- isRetry: false,
923
- isFlaky: false
924
- };
925
- if (test.err) {
926
- testResult.errorMessage = test.err.message;
927
- testResult.stackTrace = test.err.stack;
928
- testResult.errorType = "AssertionError";
929
- }
930
- console.log("[QAagentic] Reporting test:", testResult.name, "-", testResult.status);
931
- await reporter.reportTest(testResult);
932
- } catch (error) {
933
- console.warn("[QAagentic] Failed to report test:", error);
934
- }
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";
935
933
  }
936
- 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);
937
939
  } catch (error) {
938
- console.warn("[QAagentic] Error in after:spec hook:", error);
940
+ console.warn("[QAagentic] Failed to report test:", error);
939
941
  }
940
- });
941
- on("task", {
942
- qagentic_endRun: async () => {
943
- try {
944
- console.log("[QAagentic] Ending test run and flushing batch");
945
- await reporter.endRun();
946
- console.log("[QAagentic] Test run completed and results sent");
947
- await new Promise((resolve) => setTimeout(resolve, 2e3));
948
- console.log("[QAagentic] All operations completed");
949
- return null;
950
- } catch (error) {
951
- console.warn("[QAagentic] Failed to end run:", error);
952
- return null;
953
- }
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);
954
957
  }
955
- });
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());
956
965
  }
957
966
 
958
967
  // src/cypress/index.ts