@trackunit/iris-app-e2e 1.8.90 → 1.8.92-alpha-192bcb42ded.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.
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLogFile = createLogFile;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importStar(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const writeFileWithPrettier_1 = require("./writeFileWithPrettier");
8
+ const isNetworkCall = (log) => {
9
+ return log.type === "cy:fetch" || log.type === "cy:request" || log.type === "cy:response" || log.type === "cy:xrh";
10
+ };
11
+ /**
12
+ * Creates log files for Cypress test runs.
13
+ * Generates separate files for all logs, errors, and network errors.
14
+ */
15
+ function createLogFile(nxRoot, logsPath, fileNameWithoutExtension, logs, logWriter) {
16
+ if (!(0, fs_1.existsSync)(logsPath)) {
17
+ fs_1.default.mkdirSync(logsPath, { recursive: true });
18
+ }
19
+ const logFilePath = path_1.default.join(logsPath, fileNameWithoutExtension);
20
+ (0, writeFileWithPrettier_1.writeFileWithPrettier)(nxRoot, logFilePath + "-all.json", JSON.stringify(logs), { flag: "a" }, logWriter);
21
+ const errorCmds = logs.filter(log => log.severity === "error" &&
22
+ // This seems to be when apollo has cancelled requests it marks it as failed to fetch only on cypress ?!??
23
+ // might be fixed by https://github.com/Trackunit/manager/pull/12917
24
+ !log.message.includes("TypeError: Failed to fetch"));
25
+ if (errorCmds.length > 0) {
26
+ (0, writeFileWithPrettier_1.writeFileWithPrettier)(nxRoot, logFilePath + "-errors.json", JSON.stringify(errorCmds), {
27
+ flag: "a",
28
+ }, logWriter);
29
+ }
30
+ const networkErrorsCmds = logs.filter(log => isNetworkCall(log) &&
31
+ !log.message.includes("Status: 200") &&
32
+ log.severity !== "success" &&
33
+ !log.message.includes("sentry.io/api/") &&
34
+ // This seems to be when apollo has cancelled requests it marks it as failed to fetch only on cypress ?!??
35
+ !log.message.includes("TypeError: Failed to fetch"));
36
+ if (networkErrorsCmds.length > 0) {
37
+ (0, writeFileWithPrettier_1.writeFileWithPrettier)(nxRoot, logFilePath + "-network-errors.json", JSON.stringify(networkErrorsCmds), {
38
+ flag: "a",
39
+ }, logWriter);
40
+ }
41
+ }
42
+ //# sourceMappingURL=createLogFile.js.map
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupPlugins = exports.defaultCypressConfig = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
6
+ const fs_1 = require("fs");
7
+ const node_xlsx_1 = require("node-xlsx");
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ const Codeowner_1 = require("../utils/Codeowner");
10
+ const fileNameBuilder_1 = require("../utils/fileNameBuilder");
11
+ const createLogFile_1 = require("./createLogFile");
12
+ /**
13
+ * Utility function to find NX workspace root by looking for nx.json or workspace.json.
14
+ * This is more reliable than hardcoded relative paths and works from any directory.
15
+ *
16
+ * @param startDir Starting directory for the search (defaults to current working directory)
17
+ * @returns {string} Absolute path to the workspace root
18
+ * @throws Error if workspace root cannot be found
19
+ */
20
+ function findWorkspaceRoot(startDir = process.cwd()) {
21
+ let currentDir = startDir;
22
+ while (currentDir !== path_1.default.dirname(currentDir)) {
23
+ if ((0, fs_1.existsSync)(path_1.default.join(currentDir, "nx.json")) || (0, fs_1.existsSync)(path_1.default.join(currentDir, "workspace.json"))) {
24
+ return currentDir;
25
+ }
26
+ currentDir = path_1.default.dirname(currentDir);
27
+ }
28
+ throw new Error("Could not find NX workspace root (nx.json or workspace.json not found)");
29
+ }
30
+ /**
31
+ * Creates default Cypress configuration for E2E testing.
32
+ * Supports both legacy string parameter (dirname) and new options object for backward compatibility.
33
+ */
34
+ const defaultCypressConfig = optionsOrDirname => {
35
+ // Support both old API (string/undefined) and new API (object) for backward compatibility
36
+ const options = typeof optionsOrDirname === "object" ? optionsOrDirname : {};
37
+ const { nxRoot: providedNxRoot, outputDirOverride, projectConfig = {}, behaviorConfig = {}, pluginConfig = {}, } = options;
38
+ // Use NX workspace detection for reliable root finding
39
+ const nxRoot = providedNxRoot ?? findWorkspaceRoot();
40
+ // For output path calculation, determine the relative path from caller to workspace root
41
+ const callerDirname = typeof optionsOrDirname === "string" ? optionsOrDirname : process.cwd();
42
+ const relativePath = path_1.default.relative(nxRoot, callerDirname);
43
+ const dotsToNxRoot = relativePath
44
+ .split(path_1.default.sep)
45
+ .map(_ => "..")
46
+ .join("/");
47
+ const envOutputDirOverride = process.env.NX_E2E_OUTPUT_DIR || outputDirOverride;
48
+ // Function to build output paths that respects the override
49
+ const buildOutputPath = (subPath) => {
50
+ if (envOutputDirOverride) {
51
+ return path_1.default.join(dotsToNxRoot, envOutputDirOverride, subPath);
52
+ }
53
+ return `${dotsToNxRoot}/dist/cypress/${relativePath}/${subPath}`;
54
+ };
55
+ return {
56
+ projectId: projectConfig.projectId ?? process.env.CYPRESS_PROJECT_ID,
57
+ defaultCommandTimeout: behaviorConfig.defaultCommandTimeout ?? 20000,
58
+ execTimeout: behaviorConfig.execTimeout ?? 300000,
59
+ taskTimeout: behaviorConfig.taskTimeout ?? 35000,
60
+ pageLoadTimeout: behaviorConfig.pageLoadTimeout ?? 35000,
61
+ // setting to undefined makes no effect on the baseUrl so child projects can override it
62
+ baseUrl: process.env.NX_FEATURE_BRANCH_BASE_URL ?? undefined,
63
+ // This avoid issues with SRI hashes changing
64
+ modifyObstructiveCode: false,
65
+ requestTimeout: behaviorConfig.requestTimeout ?? 25000,
66
+ responseTimeout: behaviorConfig.responseTimeout ?? 150000,
67
+ retries: behaviorConfig.retries ?? {
68
+ runMode: 3,
69
+ openMode: 0,
70
+ },
71
+ fixturesFolder: projectConfig.fixturesFolder ?? "./src/fixtures",
72
+ downloadsFolder: pluginConfig.outputPath ?? buildOutputPath("downloads"),
73
+ logsFolder: pluginConfig.logsFolder ?? buildOutputPath("logs"),
74
+ chromeWebSecurity: false,
75
+ reporter: "junit",
76
+ reporterOptions: {
77
+ mochaFile: buildOutputPath("results-[hash].xml"),
78
+ },
79
+ specPattern: projectConfig.specPattern ?? "src/e2e/**/*.e2e.{js,jsx,ts,tsx}",
80
+ supportFile: projectConfig.supportFile ?? "src/support/e2e.ts",
81
+ nxRoot,
82
+ fileServerFolder: ".",
83
+ video: true,
84
+ trashAssetsBeforeRuns: false, // Don't delete videos from previous test runs (important for sequential runs)
85
+ videosFolder: pluginConfig.videosFolder ?? buildOutputPath("videos"),
86
+ screenshotsFolder: pluginConfig.screenshotsFolder ?? buildOutputPath("screenshots"),
87
+ env: {
88
+ hars_folders: pluginConfig.harFolder ?? buildOutputPath("hars"),
89
+ CYPRESS_RUN_UNIQUE_ID: crypto_1.default.randomUUID(),
90
+ },
91
+ };
92
+ };
93
+ exports.defaultCypressConfig = defaultCypressConfig;
94
+ /**
95
+ * Sets up Cypress plugins for logging, tasks, and HAR generation.
96
+ * Configures terminal reporting, XLSX parsing, and HTTP archive recording.
97
+ */
98
+ const setupPlugins = (on, config, logWriter, installHarGenerator) => {
99
+ /* ---- BEGIN: Logging setup ---- */
100
+ // Read options https://github.com/archfz/cypress-terminal-report
101
+ const options = {
102
+ printLogsToFile: "always", // Ensures logs are always printed to a file
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
+ collectTestLogs: (context, logs) => {
105
+ const testName = (0, fileNameBuilder_1.fileNameBuilder)(context.test, context.state);
106
+ (0, createLogFile_1.createLogFile)(config.nxRoot, config.logsFolder, testName, logs, logWriter);
107
+ },
108
+ };
109
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
110
+ require("cypress-terminal-report/src/installLogsPrinter")(on, options);
111
+ /* ---- END: Logging setup ---- */
112
+ /* ---- BEGIN: Task setup ---- */
113
+ on("task", {
114
+ parseXlsx(filePath) {
115
+ return new Promise((resolve, reject) => {
116
+ try {
117
+ const jsonData = (0, node_xlsx_1.parse)((0, fs_1.readFileSync)(filePath));
118
+ resolve(jsonData);
119
+ }
120
+ catch (e) {
121
+ reject(e);
122
+ }
123
+ });
124
+ },
125
+ fileExists(filename) {
126
+ return (0, fs_1.existsSync)(filename);
127
+ },
128
+ });
129
+ /* ---- END: Task setup ---- */
130
+ /* ---- BEGIN: codeowner setup ---- */
131
+ const codeowner = (0, Codeowner_1.toShortTeamName)((0, Codeowner_1.getCodeowner)(config.projectRoot, config.nxRoot));
132
+ config.env.codeowner = codeowner;
133
+ /* ---- END: codeowner setup ---- */
134
+ /* ---- BEGIN: HAR setup ---- */
135
+ // Installing the HAR geneartor should happen last according to the documentation
136
+ // https://github.com/NeuraLegion/cypress-har-generator?tab=readme-ov-file#setting-up-the-plugin
137
+ installHarGenerator(on);
138
+ /* ---- END: HAR setup ---- */
139
+ return config;
140
+ };
141
+ exports.setupPlugins = setupPlugins;
142
+ //# sourceMappingURL=defaultPlugins.js.map
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNxPreset = createNxPreset;
4
+ const cypress_preset_1 = require("@nx/cypress/plugins/cypress-preset");
5
+ const nx_tsconfig_paths_plugin_1 = require("@nx/vite/plugins/nx-tsconfig-paths.plugin");
6
+ /**
7
+ * Creates the standard NX E2E preset configuration for Cypress.
8
+ * This wraps the @nx/cypress preset with our default Vite configuration.
9
+ *
10
+ * @param filename - Pass `__filename` from the calling cypress.config.ts
11
+ * @example
12
+ * ```ts
13
+ * import { createNxPreset, CypressPluginConfig, defaultCypressConfig, setupPlugins } from "@trackunit/iris-app-e2e";
14
+ * import { defineConfig } from "cypress";
15
+ *
16
+ * const nxPreset = createNxPreset(__filename);
17
+ *
18
+ * export default defineConfig({
19
+ * chromeWebSecurity: false,
20
+ * e2e: {
21
+ * ...nxPreset,
22
+ * ...defaultCypressConfig(__dirname),
23
+ * async setupNodeEvents(on, config: CypressPluginConfig) {
24
+ * await nxPreset.setupNodeEvents?.(on, config);
25
+ * return setupPlugins(on, config, formatter, installHarGenerator);
26
+ * },
27
+ * },
28
+ * });
29
+ * ```
30
+ */
31
+ function createNxPreset(filename) {
32
+ return (0, cypress_preset_1.nxE2EPreset)(filename, {
33
+ bundler: "vite",
34
+ cypressDir: "cypress",
35
+ viteConfigOverrides: {
36
+ configFile: false,
37
+ plugins: [(0, nx_tsconfig_paths_plugin_1.nxViteTsPaths)()],
38
+ },
39
+ });
40
+ }
41
+ //# sourceMappingURL=nxPreset.js.map
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeFileWithPrettier = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /* eslint-disable no-console */
6
+ const fs_1 = require("fs");
7
+ const path = tslib_1.__importStar(require("path"));
8
+ /**
9
+ * Writes a file with Prettier formatting applied.
10
+ * Automatically detects parser based on file extension.
11
+ */
12
+ const writeFileWithPrettier = async (nxRoot, filePath, content, writeOptions = { encoding: "utf-8" }, writer) => {
13
+ const prettierConfigPath = path.join(nxRoot, ".prettierrc");
14
+ const options = await writer
15
+ .resolveConfig(prettierConfigPath)
16
+ .catch(error => console.log("Prettier config error: ", error));
17
+ if (!options) {
18
+ throw new Error("Could not find prettier config");
19
+ }
20
+ if (filePath.endsWith("json")) {
21
+ options.parser = "json";
22
+ }
23
+ else {
24
+ options.parser = "typescript";
25
+ }
26
+ try {
27
+ const prettySrc = await writer.format(content, options);
28
+ (0, fs_1.writeFileSync)(filePath, prettySrc, writeOptions);
29
+ }
30
+ catch (error) {
31
+ console.error("Error in prettier.format:", error);
32
+ }
33
+ };
34
+ exports.writeFileWithPrettier = writeFileWithPrettier;
35
+ //# sourceMappingURL=writeFileWithPrettier.js.map
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupE2E = setupE2E;
4
+ const tslib_1 = require("tslib");
5
+ const installLogsCollector_1 = tslib_1.__importDefault(require("cypress-terminal-report/src/installLogsCollector"));
6
+ const setupHarRecording_1 = require("./setupHarRecording");
7
+ /**
8
+ * Sets up the E2E testing environment with HAR recording and terminal logging.
9
+ */
10
+ function setupE2E() {
11
+ (0, setupHarRecording_1.setupHarRecording)();
12
+ (0, installLogsCollector_1.default)({
13
+ xhr: {
14
+ printHeaderData: true,
15
+ printRequestData: true,
16
+ },
17
+ });
18
+ Cypress.on("uncaught:exception", (err) => {
19
+ // eslint-disable-next-line no-console
20
+ console.log("Caught Error: ", err);
21
+ // returning false here prevents Cypress from
22
+ // failing the test
23
+ return false;
24
+ });
25
+ }
26
+ const originalDescribe = globalThis.describe;
27
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
28
+ if (originalDescribe) {
29
+ const codeowner = Cypress.env("codeowner");
30
+ const addOwnerToTitle = (title) => {
31
+ return codeowner ? title + ` [${codeowner}]` : title;
32
+ };
33
+ function patchedDescribe(title, fn) {
34
+ return originalDescribe(addOwnerToTitle(title), fn);
35
+ }
36
+ patchedDescribe.only = (title, fn) => {
37
+ return originalDescribe.only(addOwnerToTitle(title), fn);
38
+ };
39
+ patchedDescribe.skip = (title, fn) => {
40
+ return originalDescribe.skip(addOwnerToTitle(title), fn);
41
+ };
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ globalThis.describe = patchedDescribe;
44
+ }
45
+ //# sourceMappingURL=defaultE2ESetup.js.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.setupHarRecording = setupHarRecording;
5
+ require("@neuralegion/cypress-har-generator/commands");
6
+ const fileNameBuilder_1 = require("../utils/fileNameBuilder");
7
+ /**
8
+ * Sets up HAR (HTTP Archive) recording for E2E tests.
9
+ * Records network activity and saves HAR files for failed tests.
10
+ */
11
+ function setupHarRecording() {
12
+ beforeEach(() => {
13
+ const harDir = Cypress.env("hars_folders");
14
+ cy.recordHar({ rootDir: harDir });
15
+ });
16
+ afterEach(function () {
17
+ if (this.currentTest.state === "failed") {
18
+ const harDir = Cypress.env("hars_folders");
19
+ const testName = (0, fileNameBuilder_1.fileNameBuilder)(`${Cypress.currentTest.titlePath[0]} - ${Cypress.currentTest.title}`, "failed", Cypress.currentRetry);
20
+ cy.saveHar({ outDir: harDir, fileName: testName });
21
+ }
22
+ });
23
+ }
24
+ //# sourceMappingURL=setupHarRecording.js.map
package/src/support.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /// <reference path="./types/cypress.d.ts" />
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const tslib_1 = require("tslib");
5
+ /**
6
+ * Browser-only exports for Cypress support files.
7
+ * These modules depend on the Cypress global and must only be imported
8
+ * in Cypress support files, NOT in cypress.config.ts or other Node.js contexts.
9
+ */
10
+ tslib_1.__exportStar(require("./commands/defaultCommands"), exports);
11
+ tslib_1.__exportStar(require("./setup/defaultE2ESetup"), exports);
12
+ tslib_1.__exportStar(require("./setup/setupHarRecording"), exports);
13
+ //# sourceMappingURL=support.js.map
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCodeowner = exports.toShortTeamName = exports.parseCodeowners = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ /**
8
+ * Parses lines from a CODEOWNERS‐style file into a mapping of patterns → owners.
9
+ * Skips blank lines and comments (lines beginning with `#`).
10
+ *
11
+ * @param {string[]} lines - Each element is a line from your CODEOWNERS file.
12
+ * @returns {Record<string, string>} An object whose keys are normalized path patterns (no leading/trailing slashes)
13
+ * and whose values are the owner (e.g. a GitHub team handle).
14
+ * @example
15
+ * ```ts
16
+ * const lines = [
17
+ * "# Our CODEOWNERS",
18
+ * "/src @team/backend",
19
+ * "README.md @team/docs",
20
+ * "", // blank lines ignored
21
+ * "# end of file"
22
+ * ];
23
+ * const owners = parseCodeowners(lines);
24
+ * // → { "src": "@team/backend", "README.md": "@team/docs" }
25
+ * ```
26
+ */
27
+ const parseCodeowners = (lines) => {
28
+ const patterns = {};
29
+ for (const line of lines) {
30
+ const trimmed = line.trim();
31
+ if (!trimmed || trimmed.startsWith("#")) {
32
+ continue;
33
+ }
34
+ const [pattern, owner] = trimmed.split(/\s+/, 2);
35
+ if (pattern && owner) {
36
+ const normalizedPattern = pattern.replace(/^\/+|\/+$/g, "");
37
+ patterns[normalizedPattern] = owner;
38
+ }
39
+ }
40
+ return patterns;
41
+ };
42
+ exports.parseCodeowners = parseCodeowners;
43
+ /**
44
+ * Converts a full team handle (potentially namespaced and with platform suffix)
45
+ * into its “short” team name.
46
+ *
47
+ * - Strips any leading `@org/` prefix
48
+ * - Removes `-be` or `-fe` suffix if present
49
+ *
50
+ * @param {string} teamName - e.g. `"@trackunit/backend-be"` or `"@trackunit/frontend-fe"`
51
+ * @returns {string} e.g. `"backend"` or `"frontend"`
52
+ * @example
53
+ * ```ts
54
+ * toShortTeamName("@trackunit/backend-be"); // → "backend"
55
+ * toShortTeamName("@trackunit/frontend-fe"); // → "frontend"
56
+ * toShortTeamName("infra"); // → "infra"
57
+ * ```
58
+ */
59
+ const toShortTeamName = (teamName) => {
60
+ if (!teamName) {
61
+ return undefined;
62
+ }
63
+ let shortName = teamName;
64
+ if (teamName.startsWith("@")) {
65
+ shortName = shortName.slice(shortName.indexOf("/") + 1);
66
+ }
67
+ if (shortName.endsWith("-be") || shortName.endsWith("-fe")) {
68
+ shortName = shortName.slice(0, shortName.lastIndexOf("-"));
69
+ }
70
+ return shortName;
71
+ };
72
+ exports.toShortTeamName = toShortTeamName;
73
+ /**
74
+ * Recursively looks up the CODEOWNER for a given file or directory path
75
+ * by reading your workspace’s CODEOWNERS file.
76
+ *
77
+ * Walks up the directory tree until it finds a matching pattern. If no
78
+ * deeper match is found but there is a `"."` entry, returns that.
79
+ *
80
+ * @param {string} currentPath - Absolute path to the file/directory you’re querying.
81
+ * @param {string} workspaceRoot - Absolute path to your repo/workspace root.
82
+ * @param {string} [codeownersFileName="TEAM_CODEOWNERS"] - Filename to read at the root.
83
+ * @returns {string|undefined} The owner handle (e.g. `"@team/backend"`) or `undefined` if none found.
84
+ * @example
85
+ * ```ts
86
+ * // Suppose your repo root has a TEAM_CODEOWNERS file containing:
87
+ * // src @team/backend
88
+ * // src/utils @team/utils
89
+ * // . @team/root
90
+ *
91
+ * const owner1 = getCodeowner(
92
+ * "/Users/alice/project/src/utils/helpers.ts",
93
+ * "/Users/alice/project"
94
+ * );
95
+ * // → "@team/utils"
96
+ *
97
+ * const owner2 = getCodeowner(
98
+ * "/Users/alice/project/other/file.txt",
99
+ * "/Users/alice/project"
100
+ * );
101
+ * // → "@team/root" (falls back to the "." entry)
102
+ * ```
103
+ */
104
+ const getCodeowner = (currentPath, workspaceRoot, codeownersFileName = "TEAM_CODEOWNERS") => {
105
+ if (!workspaceRoot) {
106
+ return undefined;
107
+ }
108
+ const codeownersPath = path_1.default.join(workspaceRoot, codeownersFileName);
109
+ if (!fs_1.default.existsSync(codeownersPath)) {
110
+ return undefined;
111
+ }
112
+ const codeownersLines = fs_1.default.readFileSync(codeownersPath, "utf8").split("\n");
113
+ const codeowners = (0, exports.parseCodeowners)(codeownersLines);
114
+ let relPath = path_1.default
115
+ .relative(workspaceRoot, currentPath)
116
+ .replace(/\\/g, "/")
117
+ .replace(/^\/+|\/+$/g, "");
118
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
119
+ while (true) {
120
+ const codeowner = codeowners[relPath];
121
+ if (codeowner) {
122
+ return codeowner;
123
+ }
124
+ const parent = path_1.default.posix.dirname(relPath);
125
+ if ((parent === relPath || parent === ".") && codeowners["."]) {
126
+ return codeowners["."];
127
+ }
128
+ if (parent === relPath || parent === ".") {
129
+ break;
130
+ }
131
+ relPath = parent;
132
+ }
133
+ return undefined;
134
+ };
135
+ exports.getCodeowner = getCodeowner;
136
+ //# sourceMappingURL=Codeowner.js.map
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeForFilename = sanitizeForFilename;
4
+ exports.fileNameBuilder = fileNameBuilder;
5
+ /**
6
+ * Sanitizes a string to be safe for use in filenames.
7
+ * Removes special characters and truncates if too long.
8
+ *
9
+ * @param str - The string to sanitize (e.g., test suite or test name)
10
+ * @returns {string} Sanitized string safe for filesystem use
11
+ */
12
+ function sanitizeForFilename(str) {
13
+ return str
14
+ .replace(/[^a-zA-Z0-9-_\s\[\]\(\)]/g, "") // Remove special chars - with exceptions
15
+ .replace(/-+/g, "-") // Collapse multiple hyphens into one
16
+ .replace(/\s+/g, " ") // Collapse multiple spaces into one
17
+ .replace(/^-|-$/g, ""); // Trim leading/trailing hyphens
18
+ }
19
+ /**
20
+ * Builds a standardized filename for test artifacts (e.g., HAR files, screenshots).
21
+ * Combines test name, state, and attempt number into a readable filename.
22
+ *
23
+ * @param testName - The name of the test (will be sanitized)
24
+ * @param state - The test state (e.g., 'passed', 'failed')
25
+ * @param currentRetry - The current retry attempt number (0-based)
26
+ * @returns {string} A sanitized filename in the format: "testName (state) (attempt N)"
27
+ * @example
28
+ * fileNameBuilder("Login Flow", "failed", 0)
29
+ * // Returns: "Login Flow (failed) (attempt 1)"
30
+ * @example
31
+ * fileNameBuilder("Test: with -> special chars", "passed", 2)
32
+ * // Returns: "Test with - special chars (passed) (attempt 3)"
33
+ */
34
+ function fileNameBuilder(testName, state, currentRetry) {
35
+ const fileName = `${testName} ${currentRetry !== undefined ? `(Attempt ${currentRetry + 1})` : ""} (${state.toLowerCase()})`;
36
+ return sanitizeForFilename(fileName);
37
+ }
38
+ //# sourceMappingURL=fileNameBuilder.js.map
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteFileInTree = exports.updateFileInTree = void 0;
4
+ /**
5
+ *
6
+ * @param tree File system tree
7
+ * @param path Path to source file in the Tree
8
+ * @param updater Function that maps the current file content to a new to be written to the Tree
9
+ */
10
+ const updateFileInTree = (tree, path, updater) => {
11
+ if (!tree.exists(path)) {
12
+ throw new Error("File not found: " + path);
13
+ }
14
+ const fileContent = tree.read(path, "utf-8");
15
+ if (!fileContent) {
16
+ throw new Error("File is empty: " + path);
17
+ }
18
+ const result = updater(fileContent);
19
+ if (result !== fileContent) {
20
+ tree.write(path, result);
21
+ }
22
+ };
23
+ exports.updateFileInTree = updateFileInTree;
24
+ /**
25
+ *
26
+ * @param tree File system tree
27
+ * @param path Path to source file in the Tree
28
+ */
29
+ const deleteFileInTree = (tree, path) => {
30
+ if (!tree.exists(path)) {
31
+ // File doesn't exist, nothing to delete - this is fine
32
+ return;
33
+ }
34
+ tree.delete(path);
35
+ };
36
+ exports.deleteFileInTree = deleteFileInTree;
37
+ //# sourceMappingURL=fileUpdater.js.map
@@ -1 +0,0 @@
1
- exports._default = require('./index.cjs.js').default;