k6-cucumber-steps 1.1.2 → 1.1.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/cucumber.js +1 -1
- package/package.json +1 -1
- package/reports/cucumber-report.html +1 -1
- package/reports/load-report.json +84 -73
- package/scripts/linkReports.js +39 -96
- package/temp/load_script_6ae38e6d-f93e-443a-a516-587047b1f46b.js +65 -0
- package/reports/k6-report-2025-06-03T12-54-18-512Z.html +0 -582
- package/reports/k6-report-2025-06-03T12-54-33-806Z.html +0 -582
package/scripts/linkReports.js
CHANGED
|
@@ -1,122 +1,65 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const { minify } = require("html-minifier-terser");
|
|
4
3
|
|
|
5
4
|
const reportsDir = path.resolve("reports");
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function extractCucumberBody(filepath) {
|
|
13
|
-
const html = fs.readFileSync(filepath, "utf-8");
|
|
14
|
-
|
|
15
|
-
// Remove <script> tags to avoid JS conflicts
|
|
16
|
-
const withoutScripts = html.replace(/<script[\s\S]*?<\/script>/gi, "");
|
|
17
|
-
|
|
18
|
-
const match = withoutScripts.match(/<body[^>]*>([\s\S]*)<\/body>/i);
|
|
19
|
-
return match
|
|
20
|
-
? match[1]
|
|
21
|
-
: "<p>⚠️ Failed to extract body of Cucumber report.</p>";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function extractK6ReportBody(file) {
|
|
25
|
-
const html = fs.readFileSync(file, "utf-8");
|
|
26
|
-
const match = html.match(/<body[^>]*>([\s\S]*)<\/body>/i);
|
|
27
|
-
return match ? match[1] : "";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function buildCombinedHtml({ title, k6Bodies, cucumberBody }) {
|
|
31
|
-
const tabs = k6Bodies
|
|
32
|
-
.map(
|
|
33
|
-
(_, i) => `
|
|
34
|
-
<input type="radio" name="tabs" id="tabk6${i}" ${i === 0 ? "checked" : ""}>
|
|
35
|
-
<label for="tabk6${i}">K6 Report ${i + 1}</label>
|
|
36
|
-
<div class="tab">
|
|
37
|
-
${k6Bodies[i]}
|
|
38
|
-
</div>
|
|
39
|
-
`
|
|
40
|
-
)
|
|
41
|
-
.join("\n");
|
|
6
|
+
/**
|
|
7
|
+
* Adds internal cross-links between reports.
|
|
8
|
+
*/
|
|
9
|
+
function addLinksToReport(targetFile, otherFiles) {
|
|
10
|
+
const content = fs.readFileSync(targetFile, "utf-8");
|
|
42
11
|
|
|
12
|
+
// Inject the Cucumber Report tab before the Request Metrics tab
|
|
43
13
|
const cucumberTab = `
|
|
44
14
|
<input type="radio" name="tabs" id="tabcucumber">
|
|
45
|
-
<label for="tabcucumber">Cucumber Report</label>
|
|
15
|
+
<label for="tabcucumber"><i class="fas fa-file-alt"></i> Cucumber Report</label>
|
|
46
16
|
<div class="tab">
|
|
47
|
-
<
|
|
48
|
-
${cucumberBody}
|
|
49
|
-
</div>
|
|
17
|
+
<iframe src="cucumber-report.html" style="width:100%; height:600px; border:none;"></iframe>
|
|
50
18
|
</div>
|
|
51
19
|
`;
|
|
52
20
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
</style>
|
|
71
|
-
</head>
|
|
72
|
-
<body>
|
|
73
|
-
<h1>${title}</h1>
|
|
74
|
-
<div class="tabs">
|
|
75
|
-
${fullTabs}
|
|
76
|
-
</div>
|
|
77
|
-
</body>
|
|
78
|
-
</html>`;
|
|
21
|
+
const modifiedContent = content
|
|
22
|
+
.replace(
|
|
23
|
+
/<input type="radio" name="tabs" id="tabone"/,
|
|
24
|
+
`${cucumberTab}\n<input type="radio" name="tabs" id="tabone"`
|
|
25
|
+
)
|
|
26
|
+
// Remove standalone links to cucumber-report.html or k6-report.html
|
|
27
|
+
.replace(
|
|
28
|
+
/<div style="padding:10px;margin-top:20px;text-align:center">[\s\S]*?View (Cucumber|k6).*?<\/div>/,
|
|
29
|
+
""
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
fs.writeFileSync(targetFile, modifiedContent, "utf-8");
|
|
33
|
+
console.log(
|
|
34
|
+
`🔗 Updated ${path.basename(
|
|
35
|
+
targetFile
|
|
36
|
+
)} with Cucumber tab and removed standalone links.`
|
|
37
|
+
);
|
|
79
38
|
}
|
|
80
39
|
|
|
81
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Auto-link all HTML reports in the reports directory.
|
|
42
|
+
*/
|
|
43
|
+
function linkReports() {
|
|
82
44
|
if (!fs.existsSync(reportsDir)) {
|
|
83
45
|
console.warn("⚠️ No reports directory found.");
|
|
84
46
|
return;
|
|
85
47
|
}
|
|
86
48
|
|
|
87
|
-
const
|
|
88
|
-
const cucumberBody = cucumberFile
|
|
89
|
-
? extractCucumberBody(path.join(reportsDir, cucumberFile))
|
|
90
|
-
: null;
|
|
91
|
-
|
|
92
|
-
const k6Files = fs
|
|
49
|
+
const htmlFiles = fs
|
|
93
50
|
.readdirSync(reportsDir)
|
|
94
|
-
.filter((f) =>
|
|
95
|
-
|
|
96
|
-
|
|
51
|
+
.filter((f) => f.endsWith(".html"))
|
|
52
|
+
.map((f) => path.join(reportsDir, f));
|
|
53
|
+
|
|
54
|
+
if (htmlFiles.length < 2) {
|
|
55
|
+
console.warn("⚠️ Not enough HTML files to link.");
|
|
97
56
|
return;
|
|
98
57
|
}
|
|
99
58
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const combinedHtml = buildCombinedHtml({
|
|
105
|
-
title: "Combined K6 + Cucumber Report",
|
|
106
|
-
k6Bodies,
|
|
107
|
-
cucumberBody,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const finalHtml = await minify(combinedHtml, {
|
|
111
|
-
collapseWhitespace: true,
|
|
112
|
-
removeComments: true,
|
|
113
|
-
minifyCSS: true,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const outPath = path.join(reportsDir, "combined-report.html");
|
|
117
|
-
fs.writeFileSync(outPath, finalHtml, "utf-8");
|
|
118
|
-
|
|
119
|
-
console.log(`✅ Combined and minified report saved to: ${outPath}`);
|
|
59
|
+
for (const file of htmlFiles) {
|
|
60
|
+
const others = htmlFiles.filter((f) => f !== file);
|
|
61
|
+
addLinksToReport(file, others);
|
|
62
|
+
}
|
|
120
63
|
}
|
|
121
64
|
|
|
122
65
|
module.exports = { linkReports };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
import http from 'k6/http';
|
|
3
|
+
import { check } from 'k6';
|
|
4
|
+
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
|
|
5
|
+
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
|
|
6
|
+
|
|
7
|
+
export const options = {
|
|
8
|
+
"vus": 10,
|
|
9
|
+
"duration": "5s",
|
|
10
|
+
"thresholds": {
|
|
11
|
+
"http_req_failed": [
|
|
12
|
+
"rate<0.05"
|
|
13
|
+
],
|
|
14
|
+
"http_req_duration": [
|
|
15
|
+
"p(95)<5000"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function () {
|
|
21
|
+
const headers = {
|
|
22
|
+
"Content-Type": "application/json"
|
|
23
|
+
};
|
|
24
|
+
const body = undefined;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const resolvedUrl0 = "https://sandbox-decide-api.indicina.net/get?foo1=bar1&foo2=bar2";
|
|
28
|
+
const res0 = http.request("GET", resolvedUrl0, null, { headers });
|
|
29
|
+
console.log(`Response Body for ${resolvedUrl0}: ${res0.body}`);
|
|
30
|
+
check(res0, {
|
|
31
|
+
"status is 2xx": (r) => r.status >= 200 && r.status < 300
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const resolvedUrl1 = "https://postman-echo.com/get?foo1=bar1&foo2=bar2";
|
|
36
|
+
const res1 = http.request("GET", resolvedUrl1, null, { headers });
|
|
37
|
+
console.log(`Response Body for ${resolvedUrl1}: ${res1.body}`);
|
|
38
|
+
check(res1, {
|
|
39
|
+
"status is 2xx": (r) => r.status >= 200 && r.status < 300
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function handleSummary(data) {
|
|
45
|
+
const outputDir = __ENV.REPORT_OUTPUT_DIR || "reports";
|
|
46
|
+
const html = htmlReport(data);
|
|
47
|
+
const cucumberReportFile = "cucumber-report.html";
|
|
48
|
+
const cucumberLink = `
|
|
49
|
+
<div style="text-align:center; margin-top:20px;">
|
|
50
|
+
<a href="${cucumberReportFile}" style="font-size:18px; color:#0066cc;">
|
|
51
|
+
🔗 View Cucumber Test Report
|
|
52
|
+
</a>
|
|
53
|
+
</div>
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
57
|
+
const k6ReportFilename = `${outputDir}/k6-report-${timestamp}.html`;
|
|
58
|
+
|
|
59
|
+
console.log(`📄 K6 HTML report ${k6ReportFilename} generated successfully 👍`);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
[k6ReportFilename]: html.replace("</body>", `${cucumberLink}</body>`),
|
|
63
|
+
stdout: textSummary(data, { indent: " ", enableColors: true }),
|
|
64
|
+
};
|
|
65
|
+
}
|