k6-cucumber-steps 1.1.8 → 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.
@@ -24,8 +24,9 @@ program
24
24
  .option("-o, --overwrite", "Overwrite report files", false)
25
25
  .option("--cleanReports", "Clean the reports folder before running")
26
26
  .option("--clean", "Alias for --cleanReports")
27
+ .option("-p, --payloadPath <dir>", "Directory for payload files")
27
28
  .action(async (argv) => {
28
- const cucumberArgs = ["cucumber-js"];
29
+ // Load config file
29
30
  const configFileInput =
30
31
  argv.config || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
31
32
  const configFilePath = path.isAbsolute(configFileInput)
@@ -33,73 +34,70 @@ program
33
34
  : path.resolve(process.cwd(), configFileInput);
34
35
 
35
36
  let configOptions = {};
36
-
37
37
  if (fs.existsSync(configFilePath)) {
38
- cucumberArgs.push("--config", configFileInput);
39
38
  try {
40
39
  const loadedConfig = require(configFilePath);
41
40
  configOptions = loadedConfig.default || loadedConfig;
42
41
  } catch (err) {
43
42
  console.warn("⚠️ Could not load config file:", err.message);
44
43
  }
45
- } else {
46
- console.warn(`⚠️ Config file not found at ${configFilePath}`);
47
44
  }
48
45
 
49
- // Resolve cleanReports: CLI > ENV > config file
50
- const cleanReports =
51
- typeof argv.cleanReports === "boolean"
52
- ? argv.cleanReports
53
- : typeof argv.clean === "boolean"
54
- ? argv.clean
55
- : process.env.CLEAN_REPORTS
56
- ? process.env.CLEAN_REPORTS === "true"
57
- : configOptions.cleanReports;
58
-
59
- // Clean reports directory if needed
60
- const reportsDir = path.resolve("reports");
61
- if (cleanReports) {
62
- if (fs.existsSync(reportsDir)) {
63
- fs.rmSync(reportsDir, { recursive: true, force: true });
64
- console.log("🧹 Cleaned reports directory.");
65
- }
66
- }
67
- if (!fs.existsSync(reportsDir)) {
68
- fs.mkdirSync(reportsDir, { recursive: true });
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);
69
53
  }
70
54
 
71
- // Build featureFiles array before using it
72
- let featureFiles = [];
73
- if (argv.feature) {
74
- featureFiles.push(path.resolve(argv.feature));
75
- } else if (Array.isArray(configOptions.paths)) {
76
- featureFiles = configOptions.paths.map((f) => path.resolve(f));
55
+ // Add require
56
+ if (cucumberConfig.require && Array.isArray(cucumberConfig.require)) {
57
+ cucumberConfig.require.forEach((req) => {
58
+ cliParts.push("--require", req);
59
+ });
77
60
  }
78
61
 
79
- let baseReportName = "load-report";
80
- if (featureFiles.length === 1) {
81
- baseReportName = path.basename(featureFiles[0], ".feature");
82
- } else if (featureFiles.length > 1) {
83
- baseReportName = "multi-feature";
62
+ // Add format
63
+ if (cucumberConfig.format && Array.isArray(cucumberConfig.format)) {
64
+ cucumberConfig.format.forEach((fmt) => {
65
+ cliParts.push("--format", fmt);
66
+ });
84
67
  }
85
- const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
86
- let reportHtmlPath = path.join(reportsDir, `cucumber-report.html`);
87
68
 
88
- if (argv.reporter && !Array.isArray(configOptions.format)) {
89
- cucumberArgs.push("--format", "summary");
90
- cucumberArgs.push("--format", `html:${reportHtmlPath}`);
69
+ // Add tags
70
+ if (cucumberConfig.tags) {
71
+ cliParts.push("--tags", cucumberConfig.tags);
91
72
  }
92
73
 
93
- console.log("\n▶️ Final arguments passed to cucumber-js:");
94
- console.log(["npx", ...cucumberArgs].join(" ") + "\n");
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);
95
97
 
96
- const cucumberProcess = spawn("npx", cucumberArgs, {
98
+ // Now spawn the process
99
+ const cucumberProcess = spawn("npx", ["cucumber-js", ...cliParts], {
97
100
  stdio: "inherit",
98
- env: {
99
- ...process.env,
100
- REPORT_HTML_PATH: reportHtmlPath,
101
- K6_CUCUMBER_OVERWRITE: argv.overwrite ? "true" : "false",
102
- },
103
101
  });
104
102
 
105
103
  cucumberProcess.on("close", async (code) => {
@@ -108,7 +106,9 @@ program
108
106
  console.log("✅ k6-cucumber-steps execution completed successfully.");
109
107
  try {
110
108
  await linkReports();
111
- console.log("🔗 Reports linked successfully with embedded Cucumber tab.");
109
+ console.log(
110
+ "🔗 Reports linked successfully with embedded Cucumber tab."
111
+ );
112
112
  } catch (err) {
113
113
  console.error("⚠️ Failed to link reports:", err.message);
114
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k6-cucumber-steps",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -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}`);