k6-cucumber-steps 1.0.28 → 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.
@@ -1,13 +1,12 @@
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 argv = require("yargs")
7
+ const yargs = require("yargs");
8
+
9
+ const argv = yargs
11
10
  .usage("Usage: $0 run [options]")
12
11
  .option("feature", {
13
12
  alias: "f",
@@ -19,9 +18,14 @@ const argv = require("yargs")
19
18
  describe: "Cucumber tags to filter scenarios (e.g., @smoke)",
20
19
  type: "string",
21
20
  })
21
+ .option("configFile", {
22
+ alias: "c",
23
+ describe: "Custom cucumber config file name (default: cucumber.js)",
24
+ type: "string",
25
+ })
22
26
  .option("reporter", {
23
27
  alias: "r",
24
- describe: "Generate HTML and JSON reports in the `reports` directory",
28
+ describe: "Generate HTML and JSON reports in the reports directory",
25
29
  type: "boolean",
26
30
  default: false,
27
31
  })
@@ -33,27 +37,26 @@ const argv = require("yargs")
33
37
  })
34
38
  .help().argv;
35
39
 
36
- // Base Cucumber command and arguments
37
- const cucumberCommand = "npx";
38
40
  const cucumberArgs = [
39
41
  "cucumber-js",
40
42
  "--require-module",
41
43
  "@babel/register",
42
44
  "--require",
43
- path.resolve(
44
- process.cwd(),
45
- "node_modules",
46
- "k6-cucumber-steps",
47
- "step_definitions"
48
- ),
49
- "--require",
50
- path.resolve(process.cwd(), "step_definitions"), // Include user's local step definitions
45
+ path.resolve(__dirname, "../step_definitions"),
51
46
  "--format",
52
47
  "summary",
53
48
  "--format",
54
- "progress", // Progress bar format
49
+ "progress",
55
50
  ];
56
51
 
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
+
57
60
  // Add tags from CLI or environment variables
58
61
  if (argv.tags) {
59
62
  cucumberArgs.push("--tags", argv.tags);
@@ -70,7 +73,7 @@ if (argv.feature) {
70
73
  if (argv.reporter) {
71
74
  const reportsDir = path.resolve(process.cwd(), "reports");
72
75
  try {
73
- require("fs").mkdirSync(reportsDir, { recursive: true }); // Ensure reports directory exists
76
+ fs.mkdirSync(reportsDir, { recursive: true });
74
77
  } catch (err) {
75
78
  console.error(`Failed to create reports directory: ${err.message}`);
76
79
  process.exit(1);
@@ -83,36 +86,19 @@ if (argv.reporter) {
83
86
  );
84
87
  }
85
88
 
86
- /**
87
- * Main function to execute the Cucumber process.
88
- */
89
- async function main() {
90
- try {
91
- const cucumberProcess = spawn(cucumberCommand, cucumberArgs, {
92
- cwd: process.cwd(),
93
- stdio: "inherit", // Inherit stdout/stderr for real-time logging
94
- env: {
95
- ...process.env,
96
- K6_CUCUMBER_OVERWRITE: argv.overwrite, // Pass overwrite flag to environment
97
- },
98
- });
89
+ const cucumberProcess = spawn("npx", cucumberArgs, {
90
+ stdio: "inherit",
91
+ env: {
92
+ ...process.env,
93
+ K6_CUCUMBER_OVERWRITE: argv.overwrite ? "true" : "false",
94
+ },
95
+ });
99
96
 
100
- cucumberProcess.on("close", (code) => {
101
- if (code === 0) {
102
- console.log("-----------------------------------------");
103
- console.log("✅ k6-cucumber-steps execution completed successfully.");
104
- console.log("-----------------------------------------");
105
- } else {
106
- console.error("-----------------------------------------");
107
- console.error("❌ k6-cucumber-steps execution failed.");
108
- console.error("-----------------------------------------");
109
- }
110
- process.exit(code);
111
- });
112
- } catch (error) {
113
- console.error("An unexpected error occurred:", error.message);
114
- process.exit(1);
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.");
115
102
  }
116
- }
117
-
118
- main().catch((err) => console.error(err));
103
+ process.exit(code);
104
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k6-cucumber-steps",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -174,23 +174,19 @@ Then(
174
174
  );
175
175
  }
176
176
  try {
177
- // Generate the k6 script content
178
177
  const scriptContent = buildK6Script(this.config);
179
-
180
- // Generate the temporary k6 script file with overwrite option
181
178
  const scriptPath = await generateK6Script(
182
179
  scriptContent,
183
180
  "load",
184
- this.overwrite
181
+ process.env.K6_CUCUMBER_OVERWRITE === "true"
182
+ );
183
+ const stdout = await runK6Script(
184
+ scriptPath,
185
+ process.env.K6_CUCUMBER_OVERWRITE === "true"
185
186
  );
186
-
187
- // Run the k6 script with overwrite option
188
- const stdout = await runK6Script(scriptPath, this.overwrite);
189
-
190
187
  console.log(stdout);
191
188
  } catch (error) {
192
189
  console.error("k6 execution failed:", error.message);
193
- console.error("k6 stderr:", error.stderr); // Log stderr for debugging
194
190
  throw new Error("k6 test execution failed");
195
191
  }
196
192
  }