k6-cucumber-steps 1.0.29 → 1.0.31

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,8 +1,7 @@
1
1
  name: build
2
2
 
3
3
  on:
4
- push:
5
- branches: ["main"]
4
+ workflow_dispatch:
6
5
 
7
6
  jobs:
8
7
  release:
package/README.md CHANGED
@@ -110,17 +110,17 @@ Here's a step-by-step guide to using `k6-cucumber-steps` in your project:
110
110
  Create a `cucumber.js` file at the root of your project with the following content:
111
111
 
112
112
  ```javascript
113
- // cucumber.js
114
- require("dotenv").config();
113
+ // cucumber.js as default name but you can optionally give it any name of choice
115
114
 
116
115
  module.exports = {
117
116
  require: [
118
117
  // You can add paths to your local step definitions here if needed
119
118
  ],
119
+ reporter:true // To provide HTML and JSON report
120
120
  format: [
121
121
  "summary",
122
122
  "json:reports/load-report.json", // For JSON report
123
- "html:reports/report.html", // For HTML report (requires @cucumber/html-formatter)
123
+ "html:reports/report.html", // For HTML report
124
124
  ],
125
125
  tags: process.env.TAGS,
126
126
  overwrite: false, // Default to not overwrite the report file
@@ -129,16 +129,16 @@ Here's a step-by-step guide to using `k6-cucumber-steps` in your project:
129
129
 
130
130
  **Running Tests:**
131
131
 
132
- From the root of your project, use the CLI command:
132
+ From the root of your project, use the CLI command for default config:
133
133
 
134
134
  ```bash
135
135
  npx k6-cucumber-steps run
136
136
  ```
137
137
 
138
- You can also specify a feature file or tags:
138
+ You can also specify a configFile:
139
139
 
140
140
  ```bash
141
- npx k6-cucumber-steps run --feature features/example.feature -t "@yourTag"
141
+ npx k6-cucumber-steps run --configFile cucumber.prod.js
142
142
  ```
143
143
 
144
144
  ---
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const { spawn } = require("child_process");
6
+ const yargs = require("yargs");
7
+ require("dotenv").config();
8
+
9
+ // 🚀 Welcome Message
10
+ console.log(`
11
+ -----------------------------------------
12
+ 🚀 Starting k6-cucumber-steps execution...
13
+ -----------------------------------------
14
+ `);
15
+
16
+ const argv = yargs
17
+ .usage("Usage: $0 run [options]")
18
+ .option("feature", {
19
+ alias: "f",
20
+ describe: "Path to the feature file",
21
+ type: "string",
22
+ })
23
+ .option("tags", {
24
+ alias: "t",
25
+ describe: "Cucumber tags to filter scenarios",
26
+ type: "string",
27
+ })
28
+ .option("reporter", {
29
+ alias: "r",
30
+ describe: "Enable HTML and JSON reports",
31
+ type: "boolean",
32
+ default: false,
33
+ })
34
+ .option("overwrite", {
35
+ alias: "o",
36
+ describe: "Overwrite existing reports",
37
+ type: "boolean",
38
+ default: false,
39
+ })
40
+ .option("configFile", {
41
+ alias: "c",
42
+ describe: "Custom cucumber config file",
43
+ type: "string",
44
+ })
45
+ .help().argv;
46
+
47
+ const cucumberArgs = ["cucumber-js"];
48
+
49
+ const configFileName =
50
+ argv.configFile || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
51
+ const configFilePath = path.resolve(process.cwd(), configFileName);
52
+
53
+ console.log(`🔍 Looking for config file: ${configFileName}`);
54
+ console.log(`📁 Resolved config file path: ${configFilePath}`);
55
+
56
+ let configOptions = {};
57
+ if (fs.existsSync(configFilePath)) {
58
+ console.log("✅ Config file found, including in cucumber arguments...");
59
+ cucumberArgs.push("--config", configFileName);
60
+
61
+ try {
62
+ const loadedConfig = require(configFilePath);
63
+ configOptions = loadedConfig.default || loadedConfig;
64
+ } catch (err) {
65
+ console.warn("⚠️ Failed to load options from config file.");
66
+ }
67
+ } else {
68
+ console.warn("⚠️ Config file not found, skipping...");
69
+ }
70
+
71
+ // Tags
72
+ const tags = argv.tags || process.env.TAGS || configOptions.tags;
73
+ if (tags) {
74
+ cucumberArgs.push("--tags", tags);
75
+ }
76
+
77
+ // Feature file(s)
78
+ const feature = argv.feature || process.env.FEATURE_PATH;
79
+ if (feature) {
80
+ cucumberArgs.push(path.resolve(process.cwd(), feature));
81
+ } else if (configOptions.paths && configOptions.paths.length > 0) {
82
+ cucumberArgs.push(...configOptions.paths);
83
+ }
84
+
85
+ // Reporting
86
+ const reportsDir = path.join(process.cwd(), "reports");
87
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
88
+
89
+ const shouldGenerateReports = argv.reporter || configOptions.reporter || false;
90
+
91
+ const shouldOverwrite =
92
+ argv.overwrite ||
93
+ process.env.K6_CUCUMBER_OVERWRITE === "true" ||
94
+ configOptions.overwrite === true;
95
+
96
+ // Build base names from feature file(s)
97
+ let baseNames = [];
98
+
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"];
105
+ }
106
+
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
+ });
121
+
122
+ // Inject report formats into cucumber arguments
123
+ if (shouldGenerateReports) {
124
+ 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
+ });
132
+ }
133
+
134
+ console.log("📝 Reporter Enabled:", shouldGenerateReports);
135
+ console.log("📝 Overwrite Enabled:", shouldOverwrite);
136
+
137
+ console.log("\n▶️ Final arguments passed to cucumber-js:");
138
+ console.log(["npx", ...cucumberArgs].join(" ") + "\n");
139
+
140
+ const cucumberProcess = spawn("npx", cucumberArgs, {
141
+ stdio: "inherit",
142
+ env: {
143
+ ...process.env,
144
+ K6_CUCUMBER_OVERWRITE: shouldOverwrite ? "true" : "false",
145
+ TAGS: tags,
146
+ FEATURE_PATH: feature,
147
+ REPORT_JSON_PATH: reportPaths[0]?.json,
148
+ REPORT_HTML_PATH: reportPaths[0]?.html,
149
+ },
150
+ });
151
+
152
+ cucumberProcess.on("close", (code) => {
153
+ console.log(`\n-----------------------------------------`);
154
+ if (code === 0) {
155
+ console.log("✅ k6-cucumber-steps execution completed successfully.");
156
+ } else {
157
+ console.error("❌ k6-cucumber-steps execution failed.");
158
+ }
159
+ console.log(`-----------------------------------------\n`);
160
+ process.exit(code);
161
+ });
package/cucumber.js CHANGED
@@ -1,14 +1,14 @@
1
- // cucumber.js
2
-
3
1
  module.exports = {
4
- require: ["./step_definitions/**/*.js"],
5
- format: [
6
- "summary",
7
- "json:src/examples/reports/load-report.json",
8
- "html:src/examples/reports/report.html",
9
- ],
10
- // Specify the path to your features folder here
11
- paths: ["./src/examples/features/loadTestTemplate.feature"],
12
- tags: "@loadTest", // Default tag for load tests
13
- overwrite: false, // Default to not overwrite the report file
2
+ default: {
3
+ require: ["./step_definitions/**/*.js"],
4
+ format: [
5
+ "summary",
6
+ "json:./src/examples/reports/load-report.json",
7
+ "html:./src/examples/reports/report.html",
8
+ ],
9
+ paths: ["./src/examples/features/loadTestTemplate.feature"],
10
+ tags: process.env.TAGS,
11
+ overwrite: true,
12
+ reporter: true,
13
+ },
14
14
  };
package/index.js CHANGED
@@ -1 +1,23 @@
1
- export * from "./step_definitions/load_test_steps.js";
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k6-cucumber-steps",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  ]
32
32
  },
33
33
  "bin": {
34
- "k6-cucumber-steps": "./bin/k6-cucumber-runner.js"
34
+ "k6-cucumber-steps": "./bin/k6-cucumber-steps.js"
35
35
  },
36
36
  "keywords": [
37
37
  "k6",
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require("path");
4
- const { spawn } = require("child_process");
5
- const fs = require("fs");
6
- require("dotenv").config();
7
- const yargs = require("yargs");
8
-
9
- const argv = yargs
10
- .usage("Usage: $0 run [options]")
11
- .option("feature", {
12
- alias: "f",
13
- describe: "Path to the feature file",
14
- type: "string",
15
- })
16
- .option("tags", {
17
- alias: "t",
18
- describe: "Cucumber tags to filter scenarios (e.g., @smoke)",
19
- type: "string",
20
- })
21
- .option("configFile", {
22
- alias: "c",
23
- describe: "Custom cucumber config file name (default: cucumber.js)",
24
- type: "string",
25
- })
26
- .option("reporter", {
27
- alias: "r",
28
- describe: "Generate HTML and JSON reports in the reports directory",
29
- type: "boolean",
30
- default: false,
31
- })
32
- .option("overwrite", {
33
- alias: "o",
34
- describe: "Overwrite existing reports instead of appending them",
35
- type: "boolean",
36
- default: false,
37
- })
38
- .help().argv;
39
-
40
- const cucumberArgs = [
41
- "cucumber-js",
42
- "--require-module",
43
- "@babel/register",
44
- "--require",
45
- path.resolve(__dirname, "../step_definitions"),
46
- "--format",
47
- "summary",
48
- "--format",
49
- "progress",
50
- ];
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
-
60
- // Add tags from CLI or environment variables
61
- if (argv.tags) {
62
- cucumberArgs.push("--tags", argv.tags);
63
- } else if (process.env.TAGS) {
64
- cucumberArgs.push("--tags", process.env.TAGS);
65
- }
66
-
67
- // Add feature file if provided
68
- if (argv.feature) {
69
- cucumberArgs.push(path.resolve(process.cwd(), argv.feature));
70
- }
71
-
72
- // Add reporting options if enabled
73
- if (argv.reporter) {
74
- const reportsDir = path.resolve(process.cwd(), "reports");
75
- try {
76
- fs.mkdirSync(reportsDir, { recursive: true });
77
- } catch (err) {
78
- console.error(`Failed to create reports directory: ${err.message}`);
79
- process.exit(1);
80
- }
81
- cucumberArgs.push(
82
- "--format",
83
- `json:${path.join(reportsDir, "load-results.json")}`,
84
- "--format",
85
- `html:${path.join(reportsDir, "load-results.html")}`
86
- );
87
- }
88
-
89
- const cucumberProcess = spawn("npx", cucumberArgs, {
90
- stdio: "inherit",
91
- env: {
92
- ...process.env,
93
- K6_CUCUMBER_OVERWRITE: argv.overwrite ? "true" : "false",
94
- },
95
- });
96
-
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.");
102
- }
103
- process.exit(code);
104
- });