k6-cucumber-steps 1.2.22 → 1.2.23
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 +34 -39
- package/package.json +1 -1
package/bin/k6-cucumber-steps.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import dotenv from "dotenv";
|
|
8
|
+
import { linkReports } from "../scripts/linkReports.js";
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
dotenv.config();
|
|
11
|
+
|
|
12
|
+
// Allow __dirname in ESM
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = path.dirname(__filename);
|
|
9
15
|
|
|
10
16
|
console.log(`
|
|
11
17
|
-----------------------------------------
|
|
@@ -26,9 +32,9 @@ program
|
|
|
26
32
|
.option("--reporter", "Enable report generation", false)
|
|
27
33
|
.option("--clean", "Alias for --cleanReports", false)
|
|
28
34
|
.option("-p, --payloadPath <dir>", "Directory for payload files")
|
|
29
|
-
|
|
35
|
+
.option("--script <file>", "k6 script file to run")
|
|
36
|
+
.option("--k6Config <file>", "k6 config file to use")
|
|
30
37
|
.action(async (argv) => {
|
|
31
|
-
// Load config file
|
|
32
38
|
const configFileInput =
|
|
33
39
|
argv.config || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
|
|
34
40
|
const configFilePath = path.isAbsolute(configFileInput)
|
|
@@ -36,20 +42,16 @@ program
|
|
|
36
42
|
: path.resolve(process.cwd(), configFileInput);
|
|
37
43
|
|
|
38
44
|
let configOptions = {};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.warn("⚠️ Could not load config file:", err.message);
|
|
45
|
-
}
|
|
45
|
+
try {
|
|
46
|
+
const configModule = await import(pathToFileURL(configFilePath).href);
|
|
47
|
+
configOptions = configModule.default || configModule;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.warn("⚠️ Could not load config file:", err.message);
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
// Build the cucumber-js command from config
|
|
49
52
|
const cucumberConfig = configOptions.default || configOptions;
|
|
50
|
-
|
|
53
|
+
const cliParts = [];
|
|
51
54
|
|
|
52
|
-
// Add paths
|
|
53
55
|
if (cucumberConfig.paths && Array.isArray(cucumberConfig.paths)) {
|
|
54
56
|
cliParts.push(...cucumberConfig.paths);
|
|
55
57
|
}
|
|
@@ -57,21 +59,14 @@ program
|
|
|
57
59
|
cliParts.push(argv.feature);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
// Add require
|
|
61
62
|
if (cucumberConfig.require && Array.isArray(cucumberConfig.require)) {
|
|
62
|
-
cucumberConfig.require.forEach((req) =>
|
|
63
|
-
cliParts.push("--require", req);
|
|
64
|
-
});
|
|
63
|
+
cucumberConfig.require.forEach((req) => cliParts.push("--require", req));
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
// Add format
|
|
68
66
|
if (cucumberConfig.format && Array.isArray(cucumberConfig.format)) {
|
|
69
|
-
cucumberConfig.format.forEach((fmt) =>
|
|
70
|
-
cliParts.push("--format", fmt);
|
|
71
|
-
});
|
|
67
|
+
cucumberConfig.format.forEach((fmt) => cliParts.push("--format", fmt));
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
// Add tags
|
|
75
70
|
if (cucumberConfig.tags) {
|
|
76
71
|
cliParts.push("--tags", cucumberConfig.tags);
|
|
77
72
|
}
|
|
@@ -79,26 +74,23 @@ program
|
|
|
79
74
|
cliParts.push("--tags", argv.tags);
|
|
80
75
|
}
|
|
81
76
|
|
|
82
|
-
// Determine project root (where your main package.json is)
|
|
83
77
|
const projectRoot = process.cwd();
|
|
84
78
|
|
|
85
|
-
// Determine payload directory from CLI or config, always relative to project root
|
|
86
79
|
let payloadDirRaw =
|
|
87
80
|
argv.payloadPath ||
|
|
88
81
|
(cucumberConfig.worldParameters &&
|
|
89
82
|
cucumberConfig.worldParameters.payloadPath) ||
|
|
90
83
|
"payloads";
|
|
84
|
+
|
|
91
85
|
const payloadDir = path.resolve(projectRoot, payloadDirRaw);
|
|
92
86
|
console.log("📦 Resolved payload path:", payloadDir);
|
|
93
87
|
|
|
94
|
-
// Add --world-parameters to CLI args
|
|
95
88
|
const worldParams = {
|
|
96
89
|
...(cucumberConfig.worldParameters || {}),
|
|
97
90
|
payloadPath: payloadDir,
|
|
98
91
|
};
|
|
99
92
|
cliParts.push("--world-parameters", JSON.stringify(worldParams));
|
|
100
93
|
|
|
101
|
-
// Add CLI options for k6 script and config
|
|
102
94
|
if (argv.script) {
|
|
103
95
|
cliParts.push("--script", argv.script);
|
|
104
96
|
}
|
|
@@ -107,12 +99,9 @@ program
|
|
|
107
99
|
}
|
|
108
100
|
|
|
109
101
|
const finalCommand = ["npx", "cucumber-js", ...cliParts].join(" ");
|
|
110
|
-
|
|
111
102
|
console.log("▶️ Final arguments passed to cucumber-js:", finalCommand);
|
|
112
103
|
|
|
113
|
-
// Collect options to pass as env vars
|
|
114
104
|
const extraEnv = {
|
|
115
|
-
// Priority: cucumberConfig > CLI
|
|
116
105
|
SAVE_K6_SCRIPT:
|
|
117
106
|
cucumberConfig.saveK6Script === true || argv.saveK6Script === true
|
|
118
107
|
? "true"
|
|
@@ -133,19 +122,19 @@ program
|
|
|
133
122
|
: "false",
|
|
134
123
|
};
|
|
135
124
|
|
|
136
|
-
// Clean reports directory if requested
|
|
137
125
|
const shouldCleanReports =
|
|
138
126
|
argv.cleanReports || argv.clean || cucumberConfig.cleanReports;
|
|
139
127
|
|
|
140
128
|
if (shouldCleanReports) {
|
|
141
129
|
const reportsDir = path.join(projectRoot, "reports");
|
|
142
|
-
|
|
143
|
-
fs.
|
|
144
|
-
fs.
|
|
130
|
+
try {
|
|
131
|
+
await fs.rm(reportsDir, { recursive: true, force: true });
|
|
132
|
+
await fs.mkdir(reportsDir, { recursive: true });
|
|
133
|
+
} catch (err) {
|
|
134
|
+
console.error("Failed to clean reports folder:", err.message);
|
|
145
135
|
}
|
|
146
136
|
}
|
|
147
137
|
|
|
148
|
-
// Now spawn the process
|
|
149
138
|
const cucumberProcess = spawn("npx", ["cucumber-js", ...cliParts], {
|
|
150
139
|
stdio: "inherit",
|
|
151
140
|
env: { ...process.env, ...extraEnv },
|
|
@@ -174,3 +163,9 @@ program
|
|
|
174
163
|
});
|
|
175
164
|
|
|
176
165
|
program.parse(process.argv);
|
|
166
|
+
|
|
167
|
+
// Helper to handle dynamic import path
|
|
168
|
+
function pathToFileURL(p) {
|
|
169
|
+
const url = new URL("file://" + path.resolve(p));
|
|
170
|
+
return url;
|
|
171
|
+
}
|