k6-cucumber-steps 1.1.11 → 1.1.13
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.
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
module.exports = function buildK6Script(config) {
|
|
2
|
-
const { method, endpoints, endpoint, body, headers, options } = config;
|
|
2
|
+
const { method, endpoints, endpoint, body, headers, options, baseUrl } = config;
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
)
|
|
8
|
-
|
|
4
|
+
// Prefer baseUrl from config (set by step/world), then env
|
|
5
|
+
const BASE_URL =
|
|
6
|
+
baseUrl ||
|
|
7
|
+
(config.worldParameters && config.worldParameters.baseUrl) ||
|
|
8
|
+
process.env.API_BASE_URL ||
|
|
9
|
+
process.env.BASE_URL;
|
|
9
10
|
|
|
10
|
-
const BASE_URL = process.env.API_BASE_URL || process.env.BASE_URL;
|
|
11
11
|
if (!BASE_URL) {
|
|
12
12
|
throw new Error(
|
|
13
|
-
"
|
|
13
|
+
"No base URL found: please provide baseUrl inline (step/world/feature) or set API_BASE_URL/BASE_URL in environment variables."
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
|
package/lib/utils/k6Runner.js
CHANGED
|
@@ -48,10 +48,9 @@ const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
|
|
48
48
|
* Runs the k6 script with custom branding.
|
|
49
49
|
* @param {string} scriptPath - Path to the k6 script file.
|
|
50
50
|
* @param {boolean} [overwrite=false] - Whether to overwrite the report file.
|
|
51
|
-
* @returns {Promise<string>} -
|
|
51
|
+
* @returns {Promise<{stdout: string, stderr: string, code: number}>} - k6 execution result.
|
|
52
52
|
*/
|
|
53
53
|
const runK6Script = async (scriptPath, overwrite = false) => {
|
|
54
|
-
// ANSI escape codes for colors
|
|
55
54
|
const chalkGreen = "\x1b[38;2;0;255;0m"; // Green
|
|
56
55
|
const chalkYellow = "\x1b[38;2;255;255;0m"; // Yellow
|
|
57
56
|
const resetColor = "\x1b[0m";
|
|
@@ -59,7 +58,7 @@ const runK6Script = async (scriptPath, overwrite = false) => {
|
|
|
59
58
|
// Custom logo with version information
|
|
60
59
|
const customLogo = `${chalkGreen} with @qaPaschalE's ${chalkYellow}k6-cucumber-steps v${packageJson.version}${resetColor}`;
|
|
61
60
|
|
|
62
|
-
return new Promise(
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
63
62
|
exec(`k6 run "${scriptPath}"`, async (error, stdout, stderr) => {
|
|
64
63
|
// Split the k6 logo lines
|
|
65
64
|
const logoLines = stdout.split("\n");
|
|
@@ -75,27 +74,17 @@ const runK6Script = async (scriptPath, overwrite = false) => {
|
|
|
75
74
|
modifiedStdout += "\n";
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
// Handle errors and cleanup
|
|
79
|
-
if (error) {
|
|
80
|
-
console.error("k6 error:", error);
|
|
81
|
-
console.error("k6 stdout:", modifiedStdout);
|
|
82
|
-
await delay(3000); // Wait for 3 seconds
|
|
83
|
-
console.error("k6 stderr:", stderr);
|
|
84
|
-
reject(new Error(`k6 test execution failed: ${error.message}`));
|
|
85
|
-
} else if (stderr) {
|
|
86
|
-
console.log("k6 stdout:", modifiedStdout);
|
|
87
|
-
await delay(3000); // Wait for 3 seconds
|
|
88
|
-
resolve(stdout);
|
|
89
|
-
} else {
|
|
90
|
-
console.log("k6 stdout:", modifiedStdout);
|
|
91
|
-
await delay(3000); // Wait for 3 seconds
|
|
92
|
-
resolve(stdout);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
77
|
// Clean up the temporary script file
|
|
96
78
|
fs.unlink(scriptPath).catch((err) =>
|
|
97
79
|
console.error("Error deleting temporary k6 script:", err)
|
|
98
80
|
);
|
|
81
|
+
|
|
82
|
+
// Always resolve with all outputs and code
|
|
83
|
+
resolve({
|
|
84
|
+
stdout: modifiedStdout,
|
|
85
|
+
stderr,
|
|
86
|
+
code: error ? error.code ?? 1 : 0,
|
|
87
|
+
});
|
|
99
88
|
});
|
|
100
89
|
});
|
|
101
90
|
};
|
package/package.json
CHANGED
|
@@ -325,19 +325,31 @@ Then(
|
|
|
325
325
|
);
|
|
326
326
|
}
|
|
327
327
|
try {
|
|
328
|
+
// Build the k6 script content
|
|
328
329
|
const scriptContent = buildK6Script(this.config);
|
|
330
|
+
|
|
331
|
+
// Generate the k6 script file
|
|
329
332
|
const scriptPath = await generateK6Script(
|
|
330
333
|
scriptContent,
|
|
331
334
|
"load",
|
|
332
335
|
process.env.K6_CUCUMBER_OVERWRITE === "true"
|
|
333
336
|
);
|
|
334
|
-
|
|
337
|
+
|
|
338
|
+
// Run the k6 script and capture output
|
|
339
|
+
const { stdout, stderr, code } = await runK6Script(
|
|
335
340
|
scriptPath,
|
|
336
341
|
process.env.K6_CUCUMBER_OVERWRITE === "true"
|
|
337
342
|
);
|
|
338
|
-
|
|
343
|
+
|
|
344
|
+
if (stdout) console.log(stdout);
|
|
345
|
+
if (stderr) console.error(stderr);
|
|
346
|
+
|
|
347
|
+
if (code !== 0) {
|
|
348
|
+
throw new Error(`k6 exited with code ${code}`);
|
|
349
|
+
}
|
|
339
350
|
} catch (error) {
|
|
340
|
-
|
|
351
|
+
// Print the full error for debugging
|
|
352
|
+
console.error("k6 execution failed:", error.stack || error);
|
|
341
353
|
throw new Error("k6 test execution failed");
|
|
342
354
|
}
|
|
343
355
|
}
|