k6-cucumber-steps 1.2.23 → 1.2.25
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
CHANGED
package/scripts/linkReports.js
CHANGED
|
@@ -1,16 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { minify } from "html-minifier-terser";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { exec } from "child_process";
|
|
6
|
+
import os from "os";
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
// ESM __dirname workaround
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
const reportsDir = path.resolve(__dirname, "../reports");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Opens a file in the default browser based on OS.
|
|
16
|
+
* @param {string} filePath - Absolute file path to open.
|
|
17
|
+
*/
|
|
18
|
+
function openInBrowser(filePath) {
|
|
19
|
+
const platform = os.platform();
|
|
20
|
+
const command =
|
|
21
|
+
platform === "darwin"
|
|
22
|
+
? `open "${filePath}"`
|
|
23
|
+
: platform === "win32"
|
|
24
|
+
? `start "" "${filePath}"`
|
|
25
|
+
: `xdg-open "${filePath}"`; // Linux
|
|
26
|
+
|
|
27
|
+
exec(command, (err) => {
|
|
28
|
+
if (err) {
|
|
29
|
+
console.error("⚠️ Failed to open the report in browser:", err.message);
|
|
30
|
+
} else {
|
|
31
|
+
console.log("🌐 Report opened in your default browser.");
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function linkReports() {
|
|
8
37
|
if (!fs.existsSync(reportsDir)) {
|
|
9
38
|
console.warn("⚠️ No reports directory found.");
|
|
10
39
|
return;
|
|
11
40
|
}
|
|
12
41
|
|
|
13
|
-
// Get all HTML files in the reports directory, excluding any with "combined-" in the name
|
|
14
42
|
const htmlFiles = fs
|
|
15
43
|
.readdirSync(reportsDir)
|
|
16
44
|
.filter((f) => f.endsWith(".html") && !f.includes("combined-"))
|
|
@@ -25,43 +53,40 @@ async function linkReports() {
|
|
|
25
53
|
return;
|
|
26
54
|
}
|
|
27
55
|
|
|
28
|
-
// Find k6 report: file starting with "k6-" or fallback to most recent
|
|
29
56
|
let k6Report = htmlFiles.find((f) => f.name.startsWith("k6-"));
|
|
30
57
|
if (!k6Report) {
|
|
31
58
|
k6Report = htmlFiles.reduce((a, b) => (a.mtime > b.mtime ? a : b));
|
|
32
59
|
}
|
|
33
60
|
|
|
34
|
-
// Find all other HTML reports (excluding k6 report)
|
|
35
61
|
const otherReports = htmlFiles.filter((f) => f.name !== k6Report.name);
|
|
36
|
-
|
|
37
62
|
if (!k6Report || otherReports.length === 0) {
|
|
38
63
|
console.warn("⚠️ K6 or any other HTML report not found.");
|
|
39
64
|
return;
|
|
40
65
|
}
|
|
41
66
|
|
|
42
|
-
// Read k6 report content
|
|
43
67
|
let content = fs.readFileSync(k6Report.path, "utf8");
|
|
44
68
|
|
|
45
|
-
// Build tabs for each other report
|
|
46
69
|
const tabs = otherReports
|
|
47
70
|
.map(
|
|
48
71
|
(report, idx) => `
|
|
49
72
|
<input type="radio" name="tabs" id="tab${idx + 2}">
|
|
50
|
-
<label for="tab${idx + 2}"><i class="fas fa-file-alt"></i> ${
|
|
73
|
+
<label for="tab${idx + 2}"><i class="fas fa-file-alt"></i> ${
|
|
74
|
+
report.name
|
|
75
|
+
}</label>
|
|
51
76
|
<div class="tab">
|
|
52
|
-
<iframe src="${
|
|
77
|
+
<iframe src="${
|
|
78
|
+
report.name
|
|
79
|
+
}" style="width:100%; height:600px; border:none;"></iframe>
|
|
53
80
|
</div>
|
|
54
81
|
`
|
|
55
82
|
)
|
|
56
83
|
.join("\n");
|
|
57
84
|
|
|
58
|
-
// Insert tabs after the first tab (assumes k6 report has a tab structure)
|
|
59
85
|
content = content.replace(
|
|
60
86
|
/<input type="radio" name="tabs" id="tabone"/,
|
|
61
87
|
`${tabs}\n<input type="radio" name="tabs" id="tabone"`
|
|
62
88
|
);
|
|
63
89
|
|
|
64
|
-
// Remove any existing footer
|
|
65
90
|
content = content.replace(
|
|
66
91
|
/<div style="padding:10px;margin-top:20px;text-align:center">[\s\S]*?<\/div>/,
|
|
67
92
|
""
|
|
@@ -77,6 +102,6 @@ async function linkReports() {
|
|
|
77
102
|
fs.writeFileSync(combinedPath, minified, "utf8");
|
|
78
103
|
|
|
79
104
|
console.log(`📄 Combined report generated at: ${combinedPath}`);
|
|
80
|
-
}
|
|
81
105
|
|
|
82
|
-
|
|
106
|
+
openInBrowser(combinedPath);
|
|
107
|
+
}
|
|
@@ -15,7 +15,7 @@ import resolveBody from "../lib/helpers/resolveBody.js";
|
|
|
15
15
|
// import buildK6Script from "../lib/helpers/buildK6Script.js";
|
|
16
16
|
import generateHeaders from "../lib/helpers/generateHeaders.js";
|
|
17
17
|
// import { runK6Script } from "../lib/utils/k6Runner.js";
|
|
18
|
-
import { runK6ScriptFromWorld } from "
|
|
18
|
+
import { runK6ScriptFromWorld } from "../lib/helpers/runK6ScriptFromWorld.js";
|
|
19
19
|
|
|
20
20
|
dotenv.config();
|
|
21
21
|
|