haven-cypress-integration 2.0.1 → 2.0.3
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/package.json +5 -1
- package/support.js +52 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "haven-cypress-integration",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Seamless Cypress integration with HAVEN test case management",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,10 +17,14 @@
|
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"files": [
|
|
19
19
|
"index.js",
|
|
20
|
+
"support.js",
|
|
20
21
|
"bin/",
|
|
21
22
|
"templates/",
|
|
22
23
|
"README.md"
|
|
23
24
|
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"mochawesome": ">=7.0.0"
|
|
27
|
+
},
|
|
24
28
|
"engines": {
|
|
25
29
|
"node": ">=16.0.0"
|
|
26
30
|
}
|
package/support.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Haven Cypress Support
|
|
3
|
+
*
|
|
4
|
+
* Import this file in your cypress/support/e2e.ts to enable:
|
|
5
|
+
* - Screenshot attachment to mochawesome HTML reports
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import 'haven-cypress-integration/support'
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const addContext = require('mochawesome/addContext');
|
|
12
|
+
|
|
13
|
+
// Sanitize filename to match Cypress's screenshot naming behavior
|
|
14
|
+
// Cypress replaces filesystem-unsafe characters with double spaces
|
|
15
|
+
function sanitizeFilename(name) {
|
|
16
|
+
// Characters Cypress replaces: / \ ? % * : | " < >
|
|
17
|
+
return name.replace(/[/\\?%*:|"<>]/g, ' ');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Attach failed test screenshots to mochawesome report
|
|
21
|
+
// This enables screenshots to appear inline in the mochawesome HTML report
|
|
22
|
+
Cypress.on('test:after:run', (test, runnable) => {
|
|
23
|
+
if (test.state === 'failed') {
|
|
24
|
+
// Build the screenshot path that Cypress creates (must match Cypress naming exactly)
|
|
25
|
+
const specName = Cypress.spec.name;
|
|
26
|
+
|
|
27
|
+
// Walk up the parent chain to get ALL describe block titles (for nested describes)
|
|
28
|
+
const titleParts = [];
|
|
29
|
+
let parent = runnable.parent;
|
|
30
|
+
while (parent && parent.title) {
|
|
31
|
+
titleParts.unshift(parent.title);
|
|
32
|
+
parent = parent.parent;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Cypress screenshot naming: {specName}/{all describes joined by ' -- '} -- {testTitle} (failed).png
|
|
36
|
+
// Must sanitize same way Cypress does for filesystem-safe filenames
|
|
37
|
+
const fullTitle = [...titleParts, test.title].join(' -- ');
|
|
38
|
+
const sanitizedTitle = sanitizeFilename(fullTitle);
|
|
39
|
+
const screenshotPath = `screenshots/${specName}/${sanitizedTitle} (failed).png`;
|
|
40
|
+
|
|
41
|
+
// Debug: Log the generated path
|
|
42
|
+
console.log('[Haven] Screenshot path generated:', screenshotPath);
|
|
43
|
+
console.log('[Haven] Title parts:', titleParts);
|
|
44
|
+
console.log('[Haven] Test title:', test.title);
|
|
45
|
+
|
|
46
|
+
// Add screenshot to mochawesome context (will appear in HTML report)
|
|
47
|
+
addContext({ test }, screenshotPath);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log('[Haven] Screenshot-to-mochawesome integration enabled');
|
|
52
|
+
|