@trackunit/iris-app-e2e 1.4.39 → 1.4.43
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.
- package/README.md +2 -0
- package/index.cjs.js +37 -5
- package/index.esm.js +37 -5
- package/package.json +2 -2
- package/src/plugins/defaultPlugins.d.ts +1 -1
- package/src/utils/fileNameBuilder.d.ts +24 -0
package/README.md
CHANGED
|
@@ -67,6 +67,7 @@ setupDefaultCommands();
|
|
|
67
67
|
Create a `cypress.config.ts` file:
|
|
68
68
|
|
|
69
69
|
#### Simple Configuration (Backward Compatible)
|
|
70
|
+
|
|
70
71
|
```typescript
|
|
71
72
|
import { defineConfig } from 'cypress';
|
|
72
73
|
import { defaultCypressConfig, setupPlugins } from '@trackunit/iris-app-e2e';
|
|
@@ -89,6 +90,7 @@ export default defineConfig({
|
|
|
89
90
|
```
|
|
90
91
|
|
|
91
92
|
#### Advanced Configuration (New API)
|
|
93
|
+
|
|
92
94
|
```typescript
|
|
93
95
|
import { defineConfig } from 'cypress';
|
|
94
96
|
import { defaultCypressConfig, setupPlugins } from '@trackunit/iris-app-e2e';
|
package/index.cjs.js
CHANGED
|
@@ -347,6 +347,40 @@ const getCodeowner = (currentPath, workspaceRoot, codeownersFileName = "TEAM_COD
|
|
|
347
347
|
return undefined;
|
|
348
348
|
};
|
|
349
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Sanitizes a string to be safe for use in filenames.
|
|
352
|
+
* Removes special characters and truncates if too long.
|
|
353
|
+
*
|
|
354
|
+
* @param str - The string to sanitize (e.g., test suite or test name)
|
|
355
|
+
* @returns {string} Sanitized string safe for filesystem use
|
|
356
|
+
*/
|
|
357
|
+
function sanitizeForFilename(str) {
|
|
358
|
+
return str
|
|
359
|
+
.replace(/[^a-zA-Z0-9-_\s\[\]\(\)]/g, "") // Remove special chars - with exceptions
|
|
360
|
+
.replace(/-+/g, "-") // Collapse multiple hyphens into one
|
|
361
|
+
.replace(/\s+/g, " ") // Collapse multiple spaces into one
|
|
362
|
+
.replace(/^-|-$/g, ""); // Trim leading/trailing hyphens
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Builds a standardized filename for test artifacts (e.g., HAR files, screenshots).
|
|
366
|
+
* Combines test name, state, and attempt number into a readable filename.
|
|
367
|
+
*
|
|
368
|
+
* @param testName - The name of the test (will be sanitized)
|
|
369
|
+
* @param state - The test state (e.g., 'passed', 'failed')
|
|
370
|
+
* @param currentRetry - The current retry attempt number (0-based)
|
|
371
|
+
* @returns {string} A sanitized filename in the format: "testName (state) (attempt N)"
|
|
372
|
+
* @example
|
|
373
|
+
* fileNameBuilder("Login Flow", "failed", 0)
|
|
374
|
+
* // Returns: "Login Flow (failed) (attempt 1)"
|
|
375
|
+
* @example
|
|
376
|
+
* fileNameBuilder("Test: with -> special chars", "passed", 2)
|
|
377
|
+
* // Returns: "Test with - special chars (passed) (attempt 3)"
|
|
378
|
+
*/
|
|
379
|
+
function fileNameBuilder(testName, state, currentRetry) {
|
|
380
|
+
const fileName = `${testName} ${currentRetry !== undefined ? `(Attempt ${currentRetry + 1})` : ""} (${state.toLowerCase()})`;
|
|
381
|
+
return sanitizeForFilename(fileName);
|
|
382
|
+
}
|
|
383
|
+
|
|
350
384
|
/**
|
|
351
385
|
* Utility function to find NX workspace root by looking for nx.json or workspace.json.
|
|
352
386
|
* This is more reliable than hardcoded relative paths and works from any directory.
|
|
@@ -417,6 +451,7 @@ const defaultCypressConfig = optionsOrDirname => {
|
|
|
417
451
|
nxRoot,
|
|
418
452
|
fileServerFolder: ".",
|
|
419
453
|
video: true,
|
|
454
|
+
trashAssetsBeforeRuns: false, // Don't delete videos from previous test runs (important for sequential runs)
|
|
420
455
|
videosFolder: pluginConfig.videosFolder ?? buildOutputPath("videos"),
|
|
421
456
|
screenshotsFolder: pluginConfig.screenshotsFolder ?? buildOutputPath("screenshots"),
|
|
422
457
|
env: {
|
|
@@ -436,10 +471,7 @@ const setupPlugins = (on, config, logWriter, installHarGenerator) => {
|
|
|
436
471
|
printLogsToFile: "always", // Ensures logs are always printed to a file
|
|
437
472
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
438
473
|
collectTestLogs: (context, logs) => {
|
|
439
|
-
const testName = context.state
|
|
440
|
-
"_" +
|
|
441
|
-
(config.currentRetry ? `( attempt ${config.currentRetry})_` : "") +
|
|
442
|
-
context.test;
|
|
474
|
+
const testName = fileNameBuilder(context.test, context.state);
|
|
443
475
|
createLogFile(config.nxRoot, config.logsFolder, testName, logs, logWriter);
|
|
444
476
|
},
|
|
445
477
|
};
|
|
@@ -491,7 +523,7 @@ function setupHarRecording() {
|
|
|
491
523
|
afterEach(function () {
|
|
492
524
|
if (this.currentTest.state === "failed") {
|
|
493
525
|
const harDir = Cypress.env("hars_folders");
|
|
494
|
-
const testName =
|
|
526
|
+
const testName = fileNameBuilder(`${Cypress.currentTest.titlePath[0]} - ${Cypress.currentTest.title}`, "failed", Cypress.currentRetry);
|
|
495
527
|
cy.saveHar({ outDir: harDir, fileName: testName });
|
|
496
528
|
}
|
|
497
529
|
});
|
package/index.esm.js
CHANGED
|
@@ -327,6 +327,40 @@ const getCodeowner = (currentPath, workspaceRoot, codeownersFileName = "TEAM_COD
|
|
|
327
327
|
return undefined;
|
|
328
328
|
};
|
|
329
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Sanitizes a string to be safe for use in filenames.
|
|
332
|
+
* Removes special characters and truncates if too long.
|
|
333
|
+
*
|
|
334
|
+
* @param str - The string to sanitize (e.g., test suite or test name)
|
|
335
|
+
* @returns {string} Sanitized string safe for filesystem use
|
|
336
|
+
*/
|
|
337
|
+
function sanitizeForFilename(str) {
|
|
338
|
+
return str
|
|
339
|
+
.replace(/[^a-zA-Z0-9-_\s\[\]\(\)]/g, "") // Remove special chars - with exceptions
|
|
340
|
+
.replace(/-+/g, "-") // Collapse multiple hyphens into one
|
|
341
|
+
.replace(/\s+/g, " ") // Collapse multiple spaces into one
|
|
342
|
+
.replace(/^-|-$/g, ""); // Trim leading/trailing hyphens
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Builds a standardized filename for test artifacts (e.g., HAR files, screenshots).
|
|
346
|
+
* Combines test name, state, and attempt number into a readable filename.
|
|
347
|
+
*
|
|
348
|
+
* @param testName - The name of the test (will be sanitized)
|
|
349
|
+
* @param state - The test state (e.g., 'passed', 'failed')
|
|
350
|
+
* @param currentRetry - The current retry attempt number (0-based)
|
|
351
|
+
* @returns {string} A sanitized filename in the format: "testName (state) (attempt N)"
|
|
352
|
+
* @example
|
|
353
|
+
* fileNameBuilder("Login Flow", "failed", 0)
|
|
354
|
+
* // Returns: "Login Flow (failed) (attempt 1)"
|
|
355
|
+
* @example
|
|
356
|
+
* fileNameBuilder("Test: with -> special chars", "passed", 2)
|
|
357
|
+
* // Returns: "Test with - special chars (passed) (attempt 3)"
|
|
358
|
+
*/
|
|
359
|
+
function fileNameBuilder(testName, state, currentRetry) {
|
|
360
|
+
const fileName = `${testName} ${currentRetry !== undefined ? `(Attempt ${currentRetry + 1})` : ""} (${state.toLowerCase()})`;
|
|
361
|
+
return sanitizeForFilename(fileName);
|
|
362
|
+
}
|
|
363
|
+
|
|
330
364
|
/**
|
|
331
365
|
* Utility function to find NX workspace root by looking for nx.json or workspace.json.
|
|
332
366
|
* This is more reliable than hardcoded relative paths and works from any directory.
|
|
@@ -397,6 +431,7 @@ const defaultCypressConfig = optionsOrDirname => {
|
|
|
397
431
|
nxRoot,
|
|
398
432
|
fileServerFolder: ".",
|
|
399
433
|
video: true,
|
|
434
|
+
trashAssetsBeforeRuns: false, // Don't delete videos from previous test runs (important for sequential runs)
|
|
400
435
|
videosFolder: pluginConfig.videosFolder ?? buildOutputPath("videos"),
|
|
401
436
|
screenshotsFolder: pluginConfig.screenshotsFolder ?? buildOutputPath("screenshots"),
|
|
402
437
|
env: {
|
|
@@ -416,10 +451,7 @@ const setupPlugins = (on, config, logWriter, installHarGenerator) => {
|
|
|
416
451
|
printLogsToFile: "always", // Ensures logs are always printed to a file
|
|
417
452
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
418
453
|
collectTestLogs: (context, logs) => {
|
|
419
|
-
const testName = context.state
|
|
420
|
-
"_" +
|
|
421
|
-
(config.currentRetry ? `( attempt ${config.currentRetry})_` : "") +
|
|
422
|
-
context.test;
|
|
454
|
+
const testName = fileNameBuilder(context.test, context.state);
|
|
423
455
|
createLogFile(config.nxRoot, config.logsFolder, testName, logs, logWriter);
|
|
424
456
|
},
|
|
425
457
|
};
|
|
@@ -471,7 +503,7 @@ function setupHarRecording() {
|
|
|
471
503
|
afterEach(function () {
|
|
472
504
|
if (this.currentTest.state === "failed") {
|
|
473
505
|
const harDir = Cypress.env("hars_folders");
|
|
474
|
-
const testName =
|
|
506
|
+
const testName = fileNameBuilder(`${Cypress.currentTest.titlePath[0]} - ${Cypress.currentTest.title}`, "failed", Cypress.currentRetry);
|
|
475
507
|
cy.saveHar({ outDir: harDir, fileName: testName });
|
|
476
508
|
}
|
|
477
509
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/iris-app-e2e",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.43",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"generators": "./generators.json",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"cypress-terminal-report": "7.0.3",
|
|
15
15
|
"node-xlsx": "^0.23.0",
|
|
16
16
|
"prettier": "^3.4.2",
|
|
17
|
-
"@trackunit/react-test-setup": "1.4.
|
|
17
|
+
"@trackunit/react-test-setup": "1.4.42"
|
|
18
18
|
},
|
|
19
19
|
"module": "./index.esm.js",
|
|
20
20
|
"main": "./index.cjs.js",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes a string to be safe for use in filenames.
|
|
3
|
+
* Removes special characters and truncates if too long.
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to sanitize (e.g., test suite or test name)
|
|
6
|
+
* @returns {string} Sanitized string safe for filesystem use
|
|
7
|
+
*/
|
|
8
|
+
export declare function sanitizeForFilename(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Builds a standardized filename for test artifacts (e.g., HAR files, screenshots).
|
|
11
|
+
* Combines test name, state, and attempt number into a readable filename.
|
|
12
|
+
*
|
|
13
|
+
* @param testName - The name of the test (will be sanitized)
|
|
14
|
+
* @param state - The test state (e.g., 'passed', 'failed')
|
|
15
|
+
* @param currentRetry - The current retry attempt number (0-based)
|
|
16
|
+
* @returns {string} A sanitized filename in the format: "testName (state) (attempt N)"
|
|
17
|
+
* @example
|
|
18
|
+
* fileNameBuilder("Login Flow", "failed", 0)
|
|
19
|
+
* // Returns: "Login Flow (failed) (attempt 1)"
|
|
20
|
+
* @example
|
|
21
|
+
* fileNameBuilder("Test: with -> special chars", "passed", 2)
|
|
22
|
+
* // Returns: "Test with - special chars (passed) (attempt 3)"
|
|
23
|
+
*/
|
|
24
|
+
export declare function fileNameBuilder(testName: string, state: string, currentRetry?: number): string;
|