๐Ÿ“ฆ juspay / hyperswitch

๐Ÿ“„ cypress.config.js ยท 68 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68const { defineConfig } = require("cypress");
const fs = require("fs-extra");
const path = require("path");

let globalState;
// Fetch from environment variable
const connectorId = process.env.CYPRESS_CONNECTOR || "service";
const reportName = process.env.REPORT_NAME || `${connectorId}_report`;

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      require("cypress-mochawesome-reporter/plugin")(on);

      on("task", {
        setGlobalState: (val) => {
          return (globalState = val || {});
        },
        getGlobalState: () => {
          return globalState || {};
        },
        cli_log: (message) => {
          console.log("Logging console message from task");
          console.log(message);
          return null;
        },
      });
      on("after:screenshot", async (details) => {
        // Full path to the screenshot file
        const screenshotPath = details.path;

        // Extract filename without extension
        const name = path.basename(
          screenshotPath,
          path.extname(screenshotPath)
        );

        // Define a new name with a connectorId
        const newName = `[${connectorId}] ${name}.png`;
        const newPath = path.join(path.dirname(screenshotPath), newName);

        try {
          await fs.rename(screenshotPath, newPath);
          console.log("Screenshot renamed successfully");
          return { path: newPath };
        } catch (err) {
          console.error("Failed to rename screenshot:", err);
        }
      });
    },
    experimentalRunAllSpecs: true,

    reporter: "cypress-mochawesome-reporter",
    reporterOptions: {
      reportDir: "cypress/reports",
      reportFilename: reportName,
      reportPageTitle: `[${connectorId}] Cypress test report`,
      embeddedScreenshots: true,
      overwrite: false,
      inlineAssets: true,
      saveJson: true,
    },
  },
  chromeWebSecurity: false,
  defaultCommandTimeout: 10000,
  pageLoadTimeout: 20000,
});