k6-cucumber-steps 1.1.6 → 1.1.8
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.
- package/bin/k6-cucumber-steps.js +95 -98
- package/package.json +4 -6
- package/scripts/cucumber.js +18 -0
package/bin/k6-cucumber-steps.js
CHANGED
|
@@ -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")
|
|
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")
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
}
|
|
26
|
+
.option("--clean", "Alias for --cleanReports")
|
|
27
|
+
.action(async (argv) => {
|
|
28
|
+
const cucumberArgs = ["cucumber-js"];
|
|
29
|
+
const configFileInput =
|
|
30
|
+
argv.config || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
|
|
31
|
+
const configFilePath = path.isAbsolute(configFileInput)
|
|
32
|
+
? configFileInput
|
|
33
|
+
: path.resolve(process.cwd(), configFileInput);
|
|
34
|
+
|
|
35
|
+
let configOptions = {};
|
|
36
|
+
|
|
37
|
+
if (fs.existsSync(configFilePath)) {
|
|
38
|
+
cucumberArgs.push("--config", configFileInput);
|
|
39
|
+
try {
|
|
40
|
+
const loadedConfig = require(configFilePath);
|
|
41
|
+
configOptions = loadedConfig.default || loadedConfig;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.warn("⚠️ Could not load config file:", err.message);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
console.warn(`⚠️ Config file not found at ${configFilePath}`);
|
|
47
|
+
}
|
|
76
48
|
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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 });
|
|
69
|
+
}
|
|
84
70
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let reportHtmlPath = path.join(reportsDir, `cucumber-report.html`);
|
|
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));
|
|
77
|
+
}
|
|
93
78
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
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";
|
|
84
|
+
}
|
|
85
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
86
|
+
let reportHtmlPath = path.join(reportsDir, `cucumber-report.html`);
|
|
98
87
|
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
if (argv.reporter && !Array.isArray(configOptions.format)) {
|
|
89
|
+
cucumberArgs.push("--format", "summary");
|
|
90
|
+
cucumberArgs.push("--format", `html:${reportHtmlPath}`);
|
|
91
|
+
}
|
|
101
92
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
console.log("\n▶️ Final arguments passed to cucumber-js:");
|
|
94
|
+
console.log(["npx", ...cucumberArgs].join(" ") + "\n");
|
|
95
|
+
|
|
96
|
+
const cucumberProcess = spawn("npx", cucumberArgs, {
|
|
97
|
+
stdio: "inherit",
|
|
98
|
+
env: {
|
|
99
|
+
...process.env,
|
|
100
|
+
REPORT_HTML_PATH: reportHtmlPath,
|
|
101
|
+
K6_CUCUMBER_OVERWRITE: argv.overwrite ? "true" : "false",
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
cucumberProcess.on("close", async (code) => {
|
|
106
|
+
if (code === 0) {
|
|
107
|
+
console.log("-----------------------------------------");
|
|
108
|
+
console.log("✅ k6-cucumber-steps execution completed successfully.");
|
|
109
|
+
try {
|
|
110
|
+
await linkReports();
|
|
111
|
+
console.log("🔗 Reports linked successfully with embedded Cucumber tab.");
|
|
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
|
+
});
|
|
110
124
|
|
|
111
|
-
|
|
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);
|
|
120
|
-
}
|
|
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
|
-
});
|
|
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.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -62,17 +62,15 @@
|
|
|
62
62
|
"@cucumber/cucumber": "*",
|
|
63
63
|
"k6": "*"
|
|
64
64
|
},
|
|
65
|
-
"
|
|
65
|
+
"dependencies": {
|
|
66
66
|
"@babel/cli": "^7.27.2",
|
|
67
67
|
"@babel/core": "^7.27.4",
|
|
68
68
|
"@babel/preset-env": "^7.27.2",
|
|
69
|
+
"@babel/register": "^7.27.1",
|
|
69
70
|
"@faker-js/faker": "^9.8.0",
|
|
70
71
|
"@types/k6": "^1.0.2",
|
|
72
|
+
"commander": "^14.0.0",
|
|
71
73
|
"dotenv": "^16.5.0",
|
|
72
74
|
"html-minifier-terser": "^7.2.0"
|
|
73
|
-
},
|
|
74
|
-
"dependencies": {
|
|
75
|
-
"@babel/register": "^7.27.1",
|
|
76
|
-
"commander": "^14.0.0"
|
|
77
75
|
}
|
|
78
76
|
}
|
|
@@ -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
|
+
};
|