k6-cucumber-steps 1.1.7 → 1.1.9

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.
@@ -19,110 +19,107 @@ program
19
19
  .command("run")
20
20
  .option("-f, --feature <path>", "Feature file path")
21
21
  .option("-t, --tags <string>", "Cucumber tags")
22
- .option("-c, --config <file>", "Custom config file") // changed from --configFile to --config
22
+ .option("-c, --config <file>", "Custom config file")
23
23
  .option("-r, --reporter", "Enable report generation", false)
24
24
  .option("-o, --overwrite", "Overwrite report files", false)
25
25
  .option("--cleanReports", "Clean the reports folder before running")
26
- .option("--clean", "Alias for --cleanReports");
26
+ .option("--clean", "Alias for --cleanReports")
27
+ .option("-p, --payloadPath <dir>", "Directory for payload files")
28
+ .action(async (argv) => {
29
+ // Load config file
30
+ const configFileInput =
31
+ argv.config || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
32
+ const configFilePath = path.isAbsolute(configFileInput)
33
+ ? configFileInput
34
+ : path.resolve(process.cwd(), configFileInput);
35
+
36
+ let configOptions = {};
37
+ if (fs.existsSync(configFilePath)) {
38
+ try {
39
+ const loadedConfig = require(configFilePath);
40
+ configOptions = loadedConfig.default || loadedConfig;
41
+ } catch (err) {
42
+ console.warn("⚠️ Could not load config file:", err.message);
43
+ }
44
+ }
27
45
 
28
- program.parse(process.argv);
46
+ // Build the cucumber-js command from config
47
+ const cucumberConfig = configOptions.default || configOptions;
48
+ let cliParts = [];
49
+
50
+ // Add paths
51
+ if (cucumberConfig.paths && Array.isArray(cucumberConfig.paths)) {
52
+ cliParts.push(...cucumberConfig.paths);
53
+ }
54
+
55
+ // Add require
56
+ if (cucumberConfig.require && Array.isArray(cucumberConfig.require)) {
57
+ cucumberConfig.require.forEach((req) => {
58
+ cliParts.push("--require", req);
59
+ });
60
+ }
29
61
 
30
- const argv = program.opts();
31
-
32
- const cucumberArgs = ["cucumber-js"];
33
-
34
- // Update all references to argv.configFile to argv.config:
35
- const configFileInput =
36
- argv.config || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
37
- const configFilePath = path.isAbsolute(configFileInput)
38
- ? configFileInput
39
- : path.resolve(process.cwd(), configFileInput);
40
-
41
- let configOptions = {};
42
-
43
- if (fs.existsSync(configFilePath)) {
44
- cucumberArgs.push("--config", configFileInput);
45
- try {
46
- const loadedConfig = require(configFilePath);
47
- configOptions = loadedConfig.default || loadedConfig;
48
- } catch (err) {
49
- console.warn("⚠️ Could not load config file:", err.message);
50
- }
51
- } else {
52
- console.warn(`⚠️ Config file not found at ${configFilePath}`);
53
- }
54
-
55
- // Resolve cleanReports: CLI > ENV > config file
56
- const cleanReports =
57
- typeof argv.cleanReports === "boolean"
58
- ? argv.cleanReports
59
- : typeof argv.clean === "boolean"
60
- ? argv.clean
61
- : process.env.CLEAN_REPORTS
62
- ? process.env.CLEAN_REPORTS === "true"
63
- : configOptions.cleanReports;
64
-
65
- // Clean reports directory if needed
66
- const reportsDir = path.resolve("reports");
67
- if (cleanReports) {
68
- if (fs.existsSync(reportsDir)) {
69
- fs.rmSync(reportsDir, { recursive: true, force: true });
70
- console.log("🧹 Cleaned reports directory.");
71
- }
72
- }
73
- if (!fs.existsSync(reportsDir)) {
74
- fs.mkdirSync(reportsDir, { recursive: true });
75
- }
76
-
77
- // Build featureFiles array before using it
78
- let featureFiles = [];
79
- if (argv.feature) {
80
- featureFiles.push(path.resolve(argv.feature));
81
- } else if (Array.isArray(configOptions.paths)) {
82
- featureFiles = configOptions.paths.map((f) => path.resolve(f));
83
- }
84
-
85
- let baseReportName = "load-report";
86
- if (featureFiles.length === 1) {
87
- baseReportName = path.basename(featureFiles[0], ".feature");
88
- } else if (featureFiles.length > 1) {
89
- baseReportName = "multi-feature";
90
- }
91
- const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
92
- let reportHtmlPath = path.join(reportsDir, `cucumber-report.html`);
93
-
94
- if (argv.reporter && !Array.isArray(configOptions.format)) {
95
- cucumberArgs.push("--format", "summary");
96
- cucumberArgs.push("--format", `html:${reportHtmlPath}`);
97
- }
98
-
99
- console.log("\n▶️ Final arguments passed to cucumber-js:");
100
- console.log(["npx", ...cucumberArgs].join(" ") + "\n");
101
-
102
- const cucumberProcess = spawn("npx", cucumberArgs, {
103
- stdio: "inherit",
104
- env: {
105
- ...process.env,
106
- REPORT_HTML_PATH: reportHtmlPath,
107
- K6_CUCUMBER_OVERWRITE: argv.overwrite ? "true" : "false",
108
- },
109
- });
110
-
111
- cucumberProcess.on("close", async (code) => {
112
- if (code === 0) {
113
- console.log("-----------------------------------------");
114
- console.log("✅ k6-cucumber-steps execution completed successfully.");
115
- try {
116
- await linkReports();
117
- console.log("🔗 Reports linked successfully with embedded Cucumber tab.");
118
- } catch (err) {
119
- console.error("⚠️ Failed to link reports:", err.message);
62
+ // Add format
63
+ if (cucumberConfig.format && Array.isArray(cucumberConfig.format)) {
64
+ cucumberConfig.format.forEach((fmt) => {
65
+ cliParts.push("--format", fmt);
66
+ });
120
67
  }
121
- console.log("-----------------------------------------");
122
- } else {
123
- console.error("-----------------------------------------");
124
- console.error(" k6-cucumber-steps execution failed.");
125
- console.error("-----------------------------------------");
126
- }
127
- process.exit(code);
128
- });
68
+
69
+ // Add tags
70
+ if (cucumberConfig.tags) {
71
+ cliParts.push("--tags", cucumberConfig.tags);
72
+ }
73
+
74
+ // Determine project root (where your main package.json is)
75
+ const projectRoot = path.resolve(__dirname, "..");
76
+
77
+ // Determine payload directory from CLI or config, always relative to project root
78
+ let payloadDirRaw =
79
+ argv.payloadPath ||
80
+ (cucumberConfig.worldParameters && cucumberConfig.worldParameters.payloadPath) ||
81
+ "payloads";
82
+ const payloadDir = path.isAbsolute(payloadDirRaw)
83
+ ? payloadDirRaw
84
+ : path.join(projectRoot, payloadDirRaw);
85
+
86
+ // Add --world-parameters to CLI args
87
+ const worldParams = {
88
+ ...(cucumberConfig.worldParameters || {}),
89
+ payloadPath: payloadDir,
90
+ };
91
+ cliParts.push("--world-parameters", JSON.stringify(worldParams));
92
+
93
+ // Add other options as needed...
94
+
95
+ const finalCommand = ["npx", "cucumber-js", ...cliParts].join(" ");
96
+ console.log("▶️ Final arguments passed to cucumber-js:", finalCommand);
97
+
98
+ // Now spawn the process
99
+ const cucumberProcess = spawn("npx", ["cucumber-js", ...cliParts], {
100
+ stdio: "inherit",
101
+ });
102
+
103
+ cucumberProcess.on("close", async (code) => {
104
+ if (code === 0) {
105
+ console.log("-----------------------------------------");
106
+ console.log("✅ k6-cucumber-steps execution completed successfully.");
107
+ try {
108
+ await linkReports();
109
+ console.log(
110
+ "🔗 Reports linked successfully with embedded Cucumber tab."
111
+ );
112
+ } catch (err) {
113
+ console.error("⚠️ Failed to link reports:", err.message);
114
+ }
115
+ console.log("-----------------------------------------");
116
+ } else {
117
+ console.error("-----------------------------------------");
118
+ console.error("❌ k6-cucumber-steps execution failed.");
119
+ console.error("-----------------------------------------");
120
+ }
121
+ process.exit(code);
122
+ });
123
+ });
124
+
125
+ program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k6-cucumber-steps",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ default: {
3
+ require: ["./step_definitions/**/*.js"],
4
+ format: [
5
+ "summary",
6
+ "json:./reports/load-report.json",
7
+ "html:./reports/cucumber-report.html",
8
+ ],
9
+ paths: ["./features/bsp.feature"],
10
+ tags: "@get",
11
+ cleanReports: true,
12
+ worldParameters: {
13
+ payloadPath: "payloads",
14
+ },
15
+ overwrite: true,
16
+ reporter: true,
17
+ },
18
+ };
@@ -184,9 +184,11 @@ When(
184
184
  );
185
185
  }
186
186
 
187
- const basePayloadPath =
188
- this.parameters?.payloadPath || path.resolve(__dirname, "../../payloads");
189
- const payloadPath = path.resolve(basePayloadPath, fileName);
187
+ const projectRoot = path.resolve(__dirname, "..", "..");
188
+ const payloadDir = this.parameters?.payloadPath || "payloads";
189
+ const payloadPath = path.isAbsolute(payloadDir)
190
+ ? path.join(payloadDir, fileName)
191
+ : path.join(__dirname, "..", "..", payloadDir, fileName);
190
192
 
191
193
  if (!fs.existsSync(payloadPath)) {
192
194
  throw new Error(`Payload file not found: ${payloadPath}`);
@@ -261,9 +263,10 @@ Then(
261
263
  When(
262
264
  "I login via POST to {string} with payload from {string}",
263
265
  async function (endpoint, fileName) {
264
- const basePayloadPath =
265
- this.parameters?.payloadPath || path.resolve(__dirname, "../../payloads");
266
- const payloadPath = path.resolve(basePayloadPath, fileName);
266
+ const payloadDir = this.parameters?.payloadPath || "payloads";
267
+ const payloadPath = path.isAbsolute(payloadDir)
268
+ ? path.join(payloadDir, fileName)
269
+ : path.join(__dirname, "..", "..", payloadDir, fileName);
267
270
 
268
271
  if (!fs.existsSync(payloadPath)) {
269
272
  throw new Error(`Payload file not found: ${payloadPath}`);