k6-cucumber-steps 1.0.32 ā 1.0.34
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/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +12 -0
- package/README.md +12 -10
- package/bin/k6-cucumber-steps.js +49 -54
- package/index.js +0 -23
- package/package.json +17 -19
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cucumber.features": [
|
|
3
|
+
"src/features/*.feature",
|
|
4
|
+
"src/features/**/*.feature",
|
|
5
|
+
"src/features/**/*.k6.feature",
|
|
6
|
+
"src/features/template/*.feature"
|
|
7
|
+
],
|
|
8
|
+
"cucumber.glue": [
|
|
9
|
+
"step_definitions/*.js",
|
|
10
|
+
"src/features/stepDefinitions/*.js"
|
|
11
|
+
]
|
|
12
|
+
}
|
package/README.md
CHANGED
|
@@ -122,6 +122,7 @@ Here's a step-by-step guide to using `k6-cucumber-steps` in your project:
|
|
|
122
122
|
"json:reports/load-report.json", // For JSON report
|
|
123
123
|
"html:reports/report.html", // For HTML report
|
|
124
124
|
],
|
|
125
|
+
paths: ["./features/*.feature"],
|
|
125
126
|
tags: process.env.TAGS,
|
|
126
127
|
overwrite: false, // Default to not overwrite the report file
|
|
127
128
|
};
|
|
@@ -172,12 +173,12 @@ Feature: API Performance Testing
|
|
|
172
173
|
When I set to run the k6 script with the following configurations:
|
|
173
174
|
| virtual_users | duration | http_req_failed | http_req_duration |
|
|
174
175
|
| 50 | 10 | rate<0.05 | p(95)<3000 |
|
|
175
|
-
And I set the following
|
|
176
|
+
And I set the following endpoints used:
|
|
176
177
|
"""
|
|
177
178
|
/api/profile
|
|
178
179
|
[https://reqres.in/api/users?page=2](https://reqres.in/api/users?page=2)
|
|
179
180
|
"""
|
|
180
|
-
And
|
|
181
|
+
And I set the authentication type to "none"
|
|
181
182
|
Then I see the API should handle the GET request successfully
|
|
182
183
|
```
|
|
183
184
|
|
|
@@ -190,9 +191,9 @@ Feature: API Performance Testing
|
|
|
190
191
|
Given I set a k6 script for POST testing
|
|
191
192
|
When I set to run the k6 script with the following configurations:
|
|
192
193
|
| virtual_users | duration | http_req_failed | http_req_duration |
|
|
193
|
-
|
|
|
194
|
-
|
|
195
|
-
And I set the following
|
|
194
|
+
| 20 | 60 | rate<0.01 | p(95)<300 |
|
|
195
|
+
When I set the authentication type to "bearer_token"
|
|
196
|
+
And I set the following endpoints used:
|
|
196
197
|
"""
|
|
197
198
|
/api/v1/users
|
|
198
199
|
"""
|
|
@@ -204,6 +205,7 @@ Feature: API Performance Testing
|
|
|
204
205
|
}
|
|
205
206
|
"""
|
|
206
207
|
Then I see the API should handle the POST request successfully
|
|
208
|
+
|
|
207
209
|
```
|
|
208
210
|
|
|
209
211
|
## Step Definitions
|
|
@@ -211,10 +213,10 @@ Feature: API Performance Testing
|
|
|
211
213
|
### Authentication Steps
|
|
212
214
|
|
|
213
215
|
```gherkin
|
|
214
|
-
When I set the authentication type
|
|
215
|
-
When I set the authentication type
|
|
216
|
-
When I set the authentication type
|
|
217
|
-
When I set the authentication type
|
|
216
|
+
When I set the authentication type to "api_key"
|
|
217
|
+
When I set the authentication type to "bearer_token"
|
|
218
|
+
When I set the authentication type to "basic"
|
|
219
|
+
When I set the authentication type to "none"
|
|
218
220
|
```
|
|
219
221
|
|
|
220
222
|
### Request Configuration Steps
|
|
@@ -223,7 +225,7 @@ When I set the authentication type is "none"
|
|
|
223
225
|
Given I set a k6 script for {word} testing
|
|
224
226
|
When I set to run the k6 script with the following configurations:
|
|
225
227
|
When I set the request headers:
|
|
226
|
-
When I set the following
|
|
228
|
+
When I set the following endpoints used:
|
|
227
229
|
When I set the following {word} body is used for {string}
|
|
228
230
|
```
|
|
229
231
|
|
package/bin/k6-cucumber-steps.js
CHANGED
|
@@ -6,7 +6,6 @@ const { spawn } = require("child_process");
|
|
|
6
6
|
const yargs = require("yargs");
|
|
7
7
|
require("dotenv").config();
|
|
8
8
|
|
|
9
|
-
// š Welcome Message
|
|
10
9
|
console.log(`
|
|
11
10
|
-----------------------------------------
|
|
12
11
|
š Starting k6-cucumber-steps execution...
|
|
@@ -50,22 +49,15 @@ const configFileName =
|
|
|
50
49
|
argv.configFile || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
|
|
51
50
|
const configFilePath = path.resolve(process.cwd(), configFileName);
|
|
52
51
|
|
|
53
|
-
console.log(`š Looking for config file: ${configFileName}`);
|
|
54
|
-
console.log(`š Resolved config file path: ${configFilePath}`);
|
|
55
|
-
|
|
56
52
|
let configOptions = {};
|
|
57
53
|
if (fs.existsSync(configFilePath)) {
|
|
58
|
-
console.log("ā
Config file found, including in cucumber arguments...");
|
|
59
54
|
cucumberArgs.push("--config", configFileName);
|
|
60
|
-
|
|
61
55
|
try {
|
|
62
56
|
const loadedConfig = require(configFilePath);
|
|
63
57
|
configOptions = loadedConfig.default || loadedConfig;
|
|
64
|
-
} catch
|
|
65
|
-
console.warn("ā ļø
|
|
58
|
+
} catch {
|
|
59
|
+
console.warn("ā ļø Could not load config file");
|
|
66
60
|
}
|
|
67
|
-
} else {
|
|
68
|
-
console.warn("ā ļø Config file not found, skipping...");
|
|
69
61
|
}
|
|
70
62
|
|
|
71
63
|
// Tags
|
|
@@ -74,66 +66,69 @@ if (tags) {
|
|
|
74
66
|
cucumberArgs.push("--tags", tags);
|
|
75
67
|
}
|
|
76
68
|
|
|
77
|
-
// Feature
|
|
78
|
-
|
|
79
|
-
if (feature) {
|
|
80
|
-
|
|
69
|
+
// Feature path(s)
|
|
70
|
+
let featureFiles = [];
|
|
71
|
+
if (argv.feature) {
|
|
72
|
+
featureFiles.push(path.resolve(argv.feature));
|
|
81
73
|
} else if (configOptions.paths && configOptions.paths.length > 0) {
|
|
82
|
-
|
|
74
|
+
featureFiles.push(...configOptions.paths);
|
|
75
|
+
}
|
|
76
|
+
if (featureFiles.length > 0) {
|
|
77
|
+
cucumberArgs.push(...featureFiles);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
//
|
|
80
|
+
// Require default step definitions
|
|
81
|
+
const defaultStepsPath = path.resolve(
|
|
82
|
+
process.cwd(),
|
|
83
|
+
"node_modules",
|
|
84
|
+
"k6-cucumber-steps",
|
|
85
|
+
"step_definitions"
|
|
86
|
+
);
|
|
87
|
+
cucumberArgs.push("--require", defaultStepsPath);
|
|
88
|
+
|
|
89
|
+
// Also require additional custom step definitions from config, if any
|
|
90
|
+
if (configOptions.require && Array.isArray(configOptions.require)) {
|
|
91
|
+
for (const reqPath of configOptions.require) {
|
|
92
|
+
cucumberArgs.push("--require", reqPath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Determine base report name
|
|
86
97
|
const reportsDir = path.join(process.cwd(), "reports");
|
|
87
98
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
88
99
|
|
|
89
|
-
|
|
100
|
+
let baseReportName = "load-results";
|
|
101
|
+
if (featureFiles.length === 1) {
|
|
102
|
+
const nameFromFeature = path.basename(featureFiles[0], ".feature");
|
|
103
|
+
baseReportName = nameFromFeature || baseReportName;
|
|
104
|
+
} else if (featureFiles.length > 1) {
|
|
105
|
+
baseReportName = "multi-feature";
|
|
106
|
+
}
|
|
90
107
|
|
|
108
|
+
const shouldGenerateReports = argv.reporter || configOptions.reporter || false;
|
|
91
109
|
const shouldOverwrite =
|
|
92
110
|
argv.overwrite ||
|
|
93
111
|
process.env.K6_CUCUMBER_OVERWRITE === "true" ||
|
|
94
112
|
configOptions.overwrite === true;
|
|
95
113
|
|
|
96
|
-
|
|
97
|
-
let
|
|
114
|
+
let reportJsonPath = path.join(reportsDir, `${baseReportName}.json`);
|
|
115
|
+
let reportHtmlPath = path.join(reportsDir, `${baseReportName}.html`);
|
|
98
116
|
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
baseNames = configOptions.paths.map((p) => path.basename(p, path.extname(p)));
|
|
103
|
-
} else {
|
|
104
|
-
baseNames = ["load-results"];
|
|
117
|
+
if (!shouldOverwrite) {
|
|
118
|
+
reportJsonPath = path.join(reportsDir, `${baseReportName}-${timestamp}.json`);
|
|
119
|
+
reportHtmlPath = path.join(reportsDir, `${baseReportName}-${timestamp}.html`);
|
|
105
120
|
}
|
|
106
121
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const jsonName = shouldOverwrite
|
|
110
|
-
? `${base}.json`
|
|
111
|
-
: `${base}-${timestamp}.json`;
|
|
112
|
-
const htmlName = shouldOverwrite
|
|
113
|
-
? `${base}.html`
|
|
114
|
-
: `${base}-${timestamp}.html`;
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
json: path.join(reportsDir, jsonName),
|
|
118
|
-
html: path.join(reportsDir, htmlName),
|
|
119
|
-
};
|
|
120
|
-
});
|
|
122
|
+
const formatInConfig =
|
|
123
|
+
Array.isArray(configOptions.format) && configOptions.format.length > 0;
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
if (shouldGenerateReports) {
|
|
125
|
+
if (shouldGenerateReports && !formatInConfig) {
|
|
124
126
|
fs.mkdirSync(reportsDir, { recursive: true });
|
|
125
|
-
|
|
126
|
-
cucumberArgs.push("--format",
|
|
127
|
-
|
|
128
|
-
reportPaths.forEach(({ json, html }) => {
|
|
129
|
-
cucumberArgs.push("--format", `json:${json}`);
|
|
130
|
-
cucumberArgs.push("--format", `html:${html}`);
|
|
131
|
-
});
|
|
127
|
+
cucumberArgs.push("--format", `summary`);
|
|
128
|
+
cucumberArgs.push("--format", `json:${reportJsonPath}`);
|
|
129
|
+
cucumberArgs.push("--format", `html:${reportHtmlPath}`);
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
console.log("š Reporter Enabled:", shouldGenerateReports);
|
|
135
|
-
console.log("š Overwrite Enabled:", shouldOverwrite);
|
|
136
|
-
|
|
137
132
|
console.log("\nā¶ļø Final arguments passed to cucumber-js:");
|
|
138
133
|
console.log(["npx", ...cucumberArgs].join(" ") + "\n");
|
|
139
134
|
|
|
@@ -143,9 +138,9 @@ const cucumberProcess = spawn("npx", cucumberArgs, {
|
|
|
143
138
|
...process.env,
|
|
144
139
|
K6_CUCUMBER_OVERWRITE: shouldOverwrite ? "true" : "false",
|
|
145
140
|
TAGS: tags,
|
|
146
|
-
FEATURE_PATH:
|
|
147
|
-
REPORT_JSON_PATH:
|
|
148
|
-
REPORT_HTML_PATH:
|
|
141
|
+
FEATURE_PATH: featureFiles.join(","),
|
|
142
|
+
REPORT_JSON_PATH: reportJsonPath,
|
|
143
|
+
REPORT_HTML_PATH: reportHtmlPath,
|
|
149
144
|
},
|
|
150
145
|
});
|
|
151
146
|
|
package/index.js
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
// Import necessary modules
|
|
2
|
-
const buildK6Script = require("./libs/helpers/buildK6Script");
|
|
3
|
-
const generateHeaders = require("./libs/helpers/generateHeaders");
|
|
4
|
-
const resolveBody = require("./libs/helpers/resolveBody");
|
|
5
|
-
const {
|
|
6
|
-
generateK6Script: generateTempK6Script,
|
|
7
|
-
runK6Script,
|
|
8
|
-
} = require("./libs/utils/k6Runner");
|
|
9
|
-
|
|
10
|
-
// Export the main functionalities of the package
|
|
11
|
-
module.exports = {
|
|
12
|
-
// Helper functions
|
|
13
|
-
buildK6Script,
|
|
14
|
-
generateHeaders,
|
|
15
|
-
resolveBody,
|
|
16
|
-
|
|
17
|
-
// k6 script generation and execution utilities
|
|
18
|
-
generateK6Script: generateTempK6Script,
|
|
19
|
-
runK6Script,
|
|
20
|
-
|
|
21
|
-
// Step definitions (optional, if users need direct access)
|
|
22
|
-
stepDefinitions: require("./step_definitions/load_test_steps"),
|
|
23
|
-
};
|
|
24
1
|
export * from "./step_definitions/load_test_steps.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "k6-cucumber-steps",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -50,23 +50,21 @@
|
|
|
50
50
|
"author": "qaPaschalE",
|
|
51
51
|
"description": "Cucumber step definitions for running k6 performance tests.",
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@babel/cli": "
|
|
54
|
-
"@babel/core": "
|
|
55
|
-
"@babel/preset-env": "
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"dotenv": "^16.5.0",
|
|
70
|
-
"yargs": "^17.7.2"
|
|
53
|
+
"@babel/cli": "latest",
|
|
54
|
+
"@babel/core": "latest",
|
|
55
|
+
"@babel/preset-env": "latest",
|
|
56
|
+
"@babel/register": "latest",
|
|
57
|
+
"@cucumber/cucumber": "latest",
|
|
58
|
+
"@faker-js/faker": "latest",
|
|
59
|
+
"@types/k6": "latest",
|
|
60
|
+
"child_process": "latest",
|
|
61
|
+
"cucumber-console-formatter": "latest",
|
|
62
|
+
"cucumber-html-reporter": "latest",
|
|
63
|
+
"dotenv": "latest",
|
|
64
|
+
"esbuild": "latest",
|
|
65
|
+
"form-data": "latest",
|
|
66
|
+
"k6": "latest",
|
|
67
|
+
"tsconfig-paths": "latest",
|
|
68
|
+
"yargs": "latest"
|
|
71
69
|
}
|
|
72
70
|
}
|