k6-cucumber-steps 1.0.27 → 1.0.29
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/README.md +10 -2
- package/bin/k6-cucumber-runner.js +64 -34
- package/cucumber.js +4 -3
- package/package.json +1 -1
- package/step_definitions/load_test_steps.js +10 -2
- package/step_definitions/world.js +7 -3
package/README.md
CHANGED
|
@@ -19,13 +19,19 @@ Run [k6](https://k6.io/) performance/load tests using [Cucumber](https://cucumbe
|
|
|
19
19
|
## ✨ Features
|
|
20
20
|
|
|
21
21
|
- ✅ Cucumber + Gherkin for writing k6 tests
|
|
22
|
+
to generate JSON and HTML reports.
|
|
23
|
+
- ✅ Flexible configuration through Cucumber data tables.
|
|
22
24
|
- ✅ Support for JSON body parsing and escaping
|
|
23
|
-
- ✅ Faker
|
|
25
|
+
- ✅ Dynamic request body generation using environment variables, Faker templates, and JSON file includes.
|
|
24
26
|
- ✅ `.env` + `K6.env`-style variable resolution (`{{API_KEY}}`)
|
|
25
27
|
- ✅ Support for headers, query params, stages
|
|
28
|
+
- ✅ Supports multiple authentication types: API key, Bearer token, Basic Auth, and No Auth.
|
|
29
|
+
|
|
26
30
|
- ✅ Clean-up of temporary k6 files after execution
|
|
27
31
|
- ✅ Built-in support for **distributed load testing** with stages
|
|
28
32
|
- ✅ TypeScript-first 🧡
|
|
33
|
+
- ✅ **Optional report overwriting**: Use the `overwrite` option to control whether reports are overwritten or appended.
|
|
34
|
+
- ✅ **Generate detailed reports**: Use the `--reporter` flag
|
|
29
35
|
|
|
30
36
|
---
|
|
31
37
|
|
|
@@ -49,7 +55,8 @@ The `run` command accepts the following options:
|
|
|
49
55
|
|
|
50
56
|
- `-f, --feature <path>`: Path to the feature file to execute.
|
|
51
57
|
- `-t, --tags <string>`: Cucumber tags to filter scenarios (e.g., `@smoke and not @regression`).
|
|
52
|
-
- `-r, --reporter`: Generate HTML and JSON reports in the `reports` directory. This is a boolean flag, so just include `-r
|
|
58
|
+
- `-r, --reporter`: Generate HTML and JSON reports in the `reports` directory. This is a boolean flag, so just include `-r, --reporter` to enable it.
|
|
59
|
+
- `-o, --overwrite`: Overwrite existing reports instead of appending them.
|
|
53
60
|
|
|
54
61
|
### Example Usage with Options
|
|
55
62
|
|
|
@@ -116,6 +123,7 @@ Here's a step-by-step guide to using `k6-cucumber-steps` in your project:
|
|
|
116
123
|
"html:reports/report.html", // For HTML report (requires @cucumber/html-formatter)
|
|
117
124
|
],
|
|
118
125
|
tags: process.env.TAGS,
|
|
126
|
+
overwrite: false, // Default to not overwrite the report file
|
|
119
127
|
};
|
|
120
128
|
```
|
|
121
129
|
|
|
@@ -1,74 +1,104 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
console.log("-----------------------------------------");
|
|
4
|
-
console.log("🚀 Starting k6-cucumber-steps execution...");
|
|
5
|
-
console.log("-----------------------------------------");
|
|
6
|
-
|
|
7
3
|
const path = require("path");
|
|
8
4
|
const { spawn } = require("child_process");
|
|
5
|
+
const fs = require("fs");
|
|
9
6
|
require("dotenv").config();
|
|
10
|
-
const
|
|
11
|
-
|
|
7
|
+
const yargs = require("yargs");
|
|
8
|
+
|
|
9
|
+
const argv = yargs
|
|
10
|
+
.usage("Usage: $0 run [options]")
|
|
12
11
|
.option("feature", {
|
|
13
12
|
alias: "f",
|
|
14
13
|
describe: "Path to the feature file",
|
|
15
14
|
type: "string",
|
|
16
|
-
})
|
|
17
|
-
.option("tags", {
|
|
15
|
+
})
|
|
16
|
+
.option("tags", {
|
|
17
|
+
alias: "t",
|
|
18
|
+
describe: "Cucumber tags to filter scenarios (e.g., @smoke)",
|
|
19
|
+
type: "string",
|
|
20
|
+
})
|
|
21
|
+
.option("configFile", {
|
|
22
|
+
alias: "c",
|
|
23
|
+
describe: "Custom cucumber config file name (default: cucumber.js)",
|
|
24
|
+
type: "string",
|
|
25
|
+
})
|
|
18
26
|
.option("reporter", {
|
|
19
27
|
alias: "r",
|
|
20
|
-
describe: "Generate reports",
|
|
28
|
+
describe: "Generate HTML and JSON reports in the reports directory",
|
|
29
|
+
type: "boolean",
|
|
30
|
+
default: false,
|
|
31
|
+
})
|
|
32
|
+
.option("overwrite", {
|
|
33
|
+
alias: "o",
|
|
34
|
+
describe: "Overwrite existing reports instead of appending them",
|
|
21
35
|
type: "boolean",
|
|
22
36
|
default: false,
|
|
23
37
|
})
|
|
24
38
|
.help().argv;
|
|
25
39
|
|
|
26
|
-
const cucumberCommand = "npx";
|
|
27
40
|
const cucumberArgs = [
|
|
28
41
|
"cucumber-js",
|
|
29
42
|
"--require-module",
|
|
30
43
|
"@babel/register",
|
|
31
44
|
"--require",
|
|
32
|
-
path.resolve(
|
|
33
|
-
process.cwd(),
|
|
34
|
-
"node_modules",
|
|
35
|
-
"k6-cucumber-steps",
|
|
36
|
-
"step_definitions"
|
|
37
|
-
),
|
|
38
|
-
"--require",
|
|
39
|
-
path.resolve(process.cwd(), "step_definitions"), // Keep the user's local step definitions as well
|
|
45
|
+
path.resolve(__dirname, "../step_definitions"),
|
|
40
46
|
"--format",
|
|
41
47
|
"summary",
|
|
42
48
|
"--format",
|
|
43
|
-
"progress",
|
|
49
|
+
"progress",
|
|
44
50
|
];
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
// Handle dynamic config file name
|
|
53
|
+
const configFileName =
|
|
54
|
+
"cucumber.js" || process.env.CUCUMBER_CONFIG_FILE || argv.configFile;
|
|
55
|
+
const cucumberConfigPath = path.resolve(process.cwd(), configFileName);
|
|
56
|
+
if (fs.existsSync(cucumberConfigPath)) {
|
|
57
|
+
cucumberArgs.push("--config", cucumberConfigPath);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Add tags from CLI or environment variables
|
|
61
|
+
if (argv.tags) {
|
|
62
|
+
cucumberArgs.push("--tags", argv.tags);
|
|
63
|
+
} else if (process.env.TAGS) {
|
|
64
|
+
cucumberArgs.push("--tags", process.env.TAGS);
|
|
65
|
+
}
|
|
48
66
|
|
|
67
|
+
// Add feature file if provided
|
|
49
68
|
if (argv.feature) {
|
|
50
69
|
cucumberArgs.push(path.resolve(process.cwd(), argv.feature));
|
|
51
70
|
}
|
|
52
71
|
|
|
72
|
+
// Add reporting options if enabled
|
|
53
73
|
if (argv.reporter) {
|
|
54
74
|
const reportsDir = path.resolve(process.cwd(), "reports");
|
|
75
|
+
try {
|
|
76
|
+
fs.mkdirSync(reportsDir, { recursive: true });
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.error(`Failed to create reports directory: ${err.message}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
55
81
|
cucumberArgs.push(
|
|
56
82
|
"--format",
|
|
57
|
-
`json:${reportsDir
|
|
83
|
+
`json:${path.join(reportsDir, "load-results.json")}`,
|
|
58
84
|
"--format",
|
|
59
|
-
`html:${reportsDir
|
|
85
|
+
`html:${path.join(reportsDir, "load-results.html")}`
|
|
60
86
|
);
|
|
61
87
|
}
|
|
62
88
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
process.exit(code);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
89
|
+
const cucumberProcess = spawn("npx", cucumberArgs, {
|
|
90
|
+
stdio: "inherit",
|
|
91
|
+
env: {
|
|
92
|
+
...process.env,
|
|
93
|
+
K6_CUCUMBER_OVERWRITE: argv.overwrite ? "true" : "false",
|
|
94
|
+
},
|
|
95
|
+
});
|
|
73
96
|
|
|
74
|
-
|
|
97
|
+
cucumberProcess.on("close", (code) => {
|
|
98
|
+
if (code === 0) {
|
|
99
|
+
console.log("✅ k6-cucumber-steps execution completed successfully.");
|
|
100
|
+
} else {
|
|
101
|
+
console.error("❌ k6-cucumber-steps execution failed.");
|
|
102
|
+
}
|
|
103
|
+
process.exit(code);
|
|
104
|
+
});
|
package/cucumber.js
CHANGED
|
@@ -4,10 +4,11 @@ module.exports = {
|
|
|
4
4
|
require: ["./step_definitions/**/*.js"],
|
|
5
5
|
format: [
|
|
6
6
|
"summary",
|
|
7
|
-
"json:reports/load-report.json",
|
|
8
|
-
"html:reports/report.html",
|
|
7
|
+
"json:src/examples/reports/load-report.json",
|
|
8
|
+
"html:src/examples/reports/report.html",
|
|
9
9
|
],
|
|
10
10
|
// Specify the path to your features folder here
|
|
11
|
-
paths: ["./features"],
|
|
11
|
+
paths: ["./src/examples/features/loadTestTemplate.feature"],
|
|
12
12
|
tags: "@loadTest", // Default tag for load tests
|
|
13
|
+
overwrite: false, // Default to not overwrite the report file
|
|
13
14
|
};
|
package/package.json
CHANGED
|
@@ -175,8 +175,16 @@ Then(
|
|
|
175
175
|
}
|
|
176
176
|
try {
|
|
177
177
|
const scriptContent = buildK6Script(this.config);
|
|
178
|
-
const scriptPath = await generateK6Script(
|
|
179
|
-
|
|
178
|
+
const scriptPath = await generateK6Script(
|
|
179
|
+
scriptContent,
|
|
180
|
+
"load",
|
|
181
|
+
process.env.K6_CUCUMBER_OVERWRITE === "true"
|
|
182
|
+
);
|
|
183
|
+
const stdout = await runK6Script(
|
|
184
|
+
scriptPath,
|
|
185
|
+
process.env.K6_CUCUMBER_OVERWRITE === "true"
|
|
186
|
+
);
|
|
187
|
+
console.log(stdout);
|
|
180
188
|
} catch (error) {
|
|
181
189
|
console.error("k6 execution failed:", error.message);
|
|
182
190
|
throw new Error("k6 test execution failed");
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
const { setWorldConstructor } = require(
|
|
1
|
+
const { setWorldConstructor } = require("@cucumber/cucumber");
|
|
2
2
|
|
|
3
3
|
class CustomWorld {
|
|
4
|
-
constructor() {
|
|
4
|
+
constructor({ parameters }) {
|
|
5
5
|
this.options = {};
|
|
6
6
|
this.configurations = {};
|
|
7
7
|
this.endpoints = [];
|
|
8
|
-
this.authType =
|
|
8
|
+
this.authType = "";
|
|
9
9
|
this.postBody = {};
|
|
10
|
+
this.overwrite =
|
|
11
|
+
parameters?.overwrite ||
|
|
12
|
+
process.env.K6_CUCUMBER_OVERWRITE === "true" ||
|
|
13
|
+
false;
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
|