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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["cucumberopen.cucumber-official"]
3
+ }
@@ -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 endpoint(s) used:
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 when the authentication type is "none"
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
- | 20 | 60 | rate<0.01 | p(95)<300 |
194
- And the authentication type is "bearer_token"
195
- And I set the following endpoint(s) used:
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 is "api_key"
215
- When I set the authentication type is "bearer_token"
216
- When I set the authentication type is "basic"
217
- When I set the authentication type is "none"
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 endpoint(s) used:
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
 
@@ -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 (err) {
65
- console.warn("āš ļø Failed to load options from config file.");
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 file(s)
78
- const feature = argv.feature || process.env.FEATURE_PATH;
79
- if (feature) {
80
- cucumberArgs.push(path.resolve(process.cwd(), feature));
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
- cucumberArgs.push(...configOptions.paths);
74
+ featureFiles.push(...configOptions.paths);
75
+ }
76
+ if (featureFiles.length > 0) {
77
+ cucumberArgs.push(...featureFiles);
83
78
  }
84
79
 
85
- // Reporting
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
- const shouldGenerateReports = argv.reporter || configOptions.reporter || false;
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
- // Build base names from feature file(s)
97
- let baseNames = [];
114
+ let reportJsonPath = path.join(reportsDir, `${baseReportName}.json`);
115
+ let reportHtmlPath = path.join(reportsDir, `${baseReportName}.html`);
98
116
 
99
- if (feature) {
100
- baseNames = [path.basename(feature, path.extname(feature))];
101
- } else if (configOptions.paths && configOptions.paths.length > 0) {
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
- // Generate report paths
108
- const reportPaths = baseNames.map((base) => {
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
- // Inject report formats into cucumber arguments
123
- if (shouldGenerateReports) {
125
+ if (shouldGenerateReports && !formatInConfig) {
124
126
  fs.mkdirSync(reportsDir, { recursive: true });
125
-
126
- cucumberArgs.push("--format", "summary");
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: feature,
147
- REPORT_JSON_PATH: reportPaths[0]?.json,
148
- REPORT_HTML_PATH: reportPaths[0]?.html,
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.32",
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": "^7.27.0",
54
- "@babel/core": "^7.26.10",
55
- "@babel/preset-env": "^7.26.9",
56
- "@types/k6": "^1.0.2",
57
- "child_process": "^1.0.2",
58
- "cucumber-console-formatter": "^1.0.0",
59
- "cucumber-html-reporter": "^6.0.0",
60
- "esbuild": "^0.25.3",
61
- "form-data": "^4.0.2",
62
- "k6": "^0.0.0",
63
- "tsconfig-paths": "^4.2.0"
64
- },
65
- "dependencies": {
66
- "@babel/register": "^7.25.9",
67
- "@cucumber/cucumber": "^11.2.0",
68
- "@faker-js/faker": "^9.7.0",
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
  }