k6-cucumber-steps 1.0.10 → 1.0.11

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,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require("path");
4
- const { spawn } = require("child_process");
4
+ const { runCucumber } = require("@cucumber/cucumber/api");
5
5
  require("dotenv").config();
6
+
6
7
  const argv = require("yargs")
7
8
  .usage("Usage: $0 run --feature <path> [options]")
8
9
  .option("feature", {
@@ -11,56 +12,46 @@ const argv = require("yargs")
11
12
  type: "string",
12
13
  demandOption: true,
13
14
  })
14
- .option("tags", { alias: "t", describe: "Cucumber tags", type: "string" })
15
- .option("reporter", {
16
- alias: "r",
17
- describe: "Generate reports",
18
- type: "boolean",
19
- default: false,
20
- })
21
15
  .help().argv;
22
16
 
23
17
  const featureFilePath = path.resolve(process.cwd(), argv.feature);
24
- const cucumberCommand = "npx";
25
- const cucumberArgs = [
26
- "cucumber-js",
27
- featureFilePath,
28
- "--require-module",
29
- "@babel/register",
30
- "--require",
31
- path.resolve(
32
- process.cwd(),
33
- "node_modules",
34
- "k6-cucumber-steps",
35
- "step_definitions"
36
- ),
37
- "--format",
38
- "summary",
39
- ];
40
-
41
- if (argv.tags) cucumberArgs.push("--tags", argv.tags);
42
- if (argv.reporter) {
43
- const reportsDir = path.resolve(process.cwd(), "reports");
44
- cucumberArgs.push(
45
- "--format",
46
- `json:${reportsDir}/load-results.json`,
47
- "--format",
48
- `html:${reportsDir}/load-results.html`
49
- );
50
- }
51
18
 
52
19
  async function main() {
53
- const fullCommand = `${cucumberCommand} ${cucumberArgs.join(" ")}`;
54
- console.log(`Running Cucumber using command: ${fullCommand}`);
20
+ try {
21
+ console.log(`Running tests for feature file: ${featureFilePath}`);
22
+
23
+ const result = await runCucumber({
24
+ argv: [
25
+ "node",
26
+ "cucumber-js",
27
+ "--require-module",
28
+ "@babel/register",
29
+ "--require",
30
+ path.resolve(
31
+ process.cwd(),
32
+ "node_modules",
33
+ "k6-cucumber-steps",
34
+ "step_definitions"
35
+ ),
36
+ ],
37
+ cwd: process.cwd(),
38
+ featurePaths: [featureFilePath],
39
+ format: ["summary"],
40
+ });
55
41
 
56
- const cucumberProcess = spawn(cucumberCommand, cucumberArgs, {
57
- cwd: process.cwd(),
58
- stdio: "inherit",
59
- });
42
+ if (!result.success) {
43
+ console.error("K6 Cucumber tests failed.");
44
+ process.exit(1);
45
+ }
60
46
 
61
- cucumberProcess.on("close", (code) => {
62
- process.exit(code);
63
- });
47
+ console.log("K6 Cucumber tests finished successfully.");
48
+ } catch (error) {
49
+ console.error("An error occurred during K6 Cucumber execution:", error);
50
+ process.exit(1);
51
+ }
64
52
  }
65
53
 
66
- main().catch((err) => console.error(err));
54
+ main().catch((err) => {
55
+ console.error("An unexpected error occurred:", err);
56
+ process.exit(1);
57
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k6-cucumber-steps",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",