k6-cucumber-steps 1.1.9 → 1.1.11
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/bin/k6-cucumber-steps.js +18 -1
- package/lib/helpers/buildK6Script.js +9 -3
- package/package.json +1 -1
- package/scripts/linkReports.js +38 -18
package/bin/k6-cucumber-steps.js
CHANGED
|
@@ -77,7 +77,8 @@ program
|
|
|
77
77
|
// Determine payload directory from CLI or config, always relative to project root
|
|
78
78
|
let payloadDirRaw =
|
|
79
79
|
argv.payloadPath ||
|
|
80
|
-
(cucumberConfig.worldParameters &&
|
|
80
|
+
(cucumberConfig.worldParameters &&
|
|
81
|
+
cucumberConfig.worldParameters.payloadPath) ||
|
|
81
82
|
"payloads";
|
|
82
83
|
const payloadDir = path.isAbsolute(payloadDirRaw)
|
|
83
84
|
? payloadDirRaw
|
|
@@ -95,6 +96,22 @@ program
|
|
|
95
96
|
const finalCommand = ["npx", "cucumber-js", ...cliParts].join(" ");
|
|
96
97
|
console.log("▶️ Final arguments passed to cucumber-js:", finalCommand);
|
|
97
98
|
|
|
99
|
+
// Clean reports directory if requested
|
|
100
|
+
const shouldCleanReports =
|
|
101
|
+
argv.cleanReports ||
|
|
102
|
+
argv.clean ||
|
|
103
|
+
process.env.CLEAN_REPORTS === "true" ||
|
|
104
|
+
cucumberConfig.cleanReports;
|
|
105
|
+
|
|
106
|
+
if (shouldCleanReports) {
|
|
107
|
+
const reportsDir = path.join(projectRoot, "reports");
|
|
108
|
+
if (fs.existsSync(reportsDir)) {
|
|
109
|
+
fs.rmSync(reportsDir, { recursive: true, force: true });
|
|
110
|
+
fs.mkdirSync(reportsDir, { recursive: true });
|
|
111
|
+
console.log("🧹 Cleaned reports directory.");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
98
115
|
// Now spawn the process
|
|
99
116
|
const cucumberProcess = spawn("npx", ["cucumber-js", ...cliParts], {
|
|
100
117
|
stdio: "inherit",
|
|
@@ -18,8 +18,14 @@ module.exports = function buildK6Script(config) {
|
|
|
18
18
|
return url.startsWith("/") ? `${BASE_URL}${url}` : url;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
const
|
|
21
|
+
// Default headers/body/options for safety
|
|
22
|
+
const safeHeaders = headers && Object.keys(headers).length ? headers : {};
|
|
23
|
+
const safeBody = body !== undefined ? body : null;
|
|
24
|
+
const safeOptions = options && Object.keys(options).length ? options : {};
|
|
25
|
+
|
|
26
|
+
// Stringify for script
|
|
27
|
+
const stringifiedHeaders = JSON.stringify(safeHeaders, null, 2);
|
|
28
|
+
const stringifiedBody = JSON.stringify(safeBody, null, 2);
|
|
23
29
|
|
|
24
30
|
return `
|
|
25
31
|
import http from 'k6/http';
|
|
@@ -27,7 +33,7 @@ import { check } from 'k6';
|
|
|
27
33
|
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
|
|
28
34
|
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
|
|
29
35
|
|
|
30
|
-
export const options = ${JSON.stringify(
|
|
36
|
+
export const options = ${JSON.stringify(safeOptions, null, 2)};
|
|
31
37
|
|
|
32
38
|
export default function () {
|
|
33
39
|
const headers = ${stringifiedHeaders};
|
package/package.json
CHANGED
package/scripts/linkReports.js
CHANGED
|
@@ -10,38 +10,58 @@ async function linkReports() {
|
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// Get all HTML files in the reports directory
|
|
13
14
|
const htmlFiles = fs
|
|
14
15
|
.readdirSync(reportsDir)
|
|
15
|
-
.filter((f) => f.endsWith(".html"))
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
.filter((f) => f.endsWith(".html"))
|
|
17
|
+
.map((f) => ({
|
|
18
|
+
name: f,
|
|
19
|
+
path: path.join(reportsDir, f),
|
|
20
|
+
mtime: fs.statSync(path.join(reportsDir, f)).mtime.getTime(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
if (htmlFiles.length === 0) {
|
|
24
|
+
console.warn("⚠️ No HTML reports found.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Find k6 report: file starting with "k6-" or fallback to most recent
|
|
29
|
+
let k6Report = htmlFiles.find((f) => f.name.startsWith("k6-"));
|
|
30
|
+
if (!k6Report) {
|
|
31
|
+
k6Report = htmlFiles.reduce((a, b) => (a.mtime > b.mtime ? a : b));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Find all other HTML reports (excluding k6 report)
|
|
35
|
+
const otherReports = htmlFiles.filter((f) => f.name !== k6Report.name);
|
|
22
36
|
|
|
23
|
-
if (!
|
|
24
|
-
console.warn("⚠️ K6 or
|
|
37
|
+
if (!k6Report || otherReports.length === 0) {
|
|
38
|
+
console.warn("⚠️ K6 or any other HTML report not found.");
|
|
25
39
|
return;
|
|
26
40
|
}
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let content = fs.readFileSync(k6Path, "utf8");
|
|
42
|
+
// Read k6 report content
|
|
43
|
+
let content = fs.readFileSync(k6Report.path, "utf8");
|
|
31
44
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
// Build tabs for each other report
|
|
46
|
+
const tabs = otherReports
|
|
47
|
+
.map(
|
|
48
|
+
(report, idx) => `
|
|
49
|
+
<input type="radio" name="tabs" id="tab${idx + 2}">
|
|
50
|
+
<label for="tab${idx + 2}"><i class="fas fa-file-alt"></i> ${report.name}</label>
|
|
35
51
|
<div class="tab">
|
|
36
|
-
<iframe src="${
|
|
52
|
+
<iframe src="${report.name}" style="width:100%; height:600px; border:none;"></iframe>
|
|
37
53
|
</div>
|
|
38
|
-
|
|
54
|
+
`
|
|
55
|
+
)
|
|
56
|
+
.join("\n");
|
|
39
57
|
|
|
58
|
+
// Insert tabs after the first tab (assumes k6 report has a tab structure)
|
|
40
59
|
content = content.replace(
|
|
41
60
|
/<input type="radio" name="tabs" id="tabone"/,
|
|
42
|
-
`${
|
|
61
|
+
`${tabs}\n<input type="radio" name="tabs" id="tabone"`
|
|
43
62
|
);
|
|
44
63
|
|
|
64
|
+
// Remove any existing footer
|
|
45
65
|
content = content.replace(
|
|
46
66
|
/<div style="padding:10px;margin-top:20px;text-align:center">[\s\S]*?<\/div>/,
|
|
47
67
|
""
|