k6-cucumber-steps 1.0.32 ā 1.0.33
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 +49 -54
- package/index.js +0 -23
- package/package.json +1 -1
package/bin/k6-cucumber-steps.js
CHANGED
|
@@ -6,7 +6,6 @@ const { spawn } = require("child_process");
|
|
|
6
6
|
const yargs = require("yargs");
|
|
7
7
|
require("dotenv").config();
|
|
8
8
|
|
|
9
|
-
// š Welcome Message
|
|
10
9
|
console.log(`
|
|
11
10
|
-----------------------------------------
|
|
12
11
|
š Starting k6-cucumber-steps execution...
|
|
@@ -50,22 +49,15 @@ const configFileName =
|
|
|
50
49
|
argv.configFile || process.env.CUCUMBER_CONFIG_FILE || "cucumber.js";
|
|
51
50
|
const configFilePath = path.resolve(process.cwd(), configFileName);
|
|
52
51
|
|
|
53
|
-
console.log(`š Looking for config file: ${configFileName}`);
|
|
54
|
-
console.log(`š Resolved config file path: ${configFilePath}`);
|
|
55
|
-
|
|
56
52
|
let configOptions = {};
|
|
57
53
|
if (fs.existsSync(configFilePath)) {
|
|
58
|
-
console.log("ā
Config file found, including in cucumber arguments...");
|
|
59
54
|
cucumberArgs.push("--config", configFileName);
|
|
60
|
-
|
|
61
55
|
try {
|
|
62
56
|
const loadedConfig = require(configFilePath);
|
|
63
57
|
configOptions = loadedConfig.default || loadedConfig;
|
|
64
|
-
} catch
|
|
65
|
-
console.warn("ā ļø
|
|
58
|
+
} catch {
|
|
59
|
+
console.warn("ā ļø Could not load config file");
|
|
66
60
|
}
|
|
67
|
-
} else {
|
|
68
|
-
console.warn("ā ļø Config file not found, skipping...");
|
|
69
61
|
}
|
|
70
62
|
|
|
71
63
|
// Tags
|
|
@@ -74,66 +66,69 @@ if (tags) {
|
|
|
74
66
|
cucumberArgs.push("--tags", tags);
|
|
75
67
|
}
|
|
76
68
|
|
|
77
|
-
// Feature
|
|
78
|
-
|
|
79
|
-
if (feature) {
|
|
80
|
-
|
|
69
|
+
// Feature path(s)
|
|
70
|
+
let featureFiles = [];
|
|
71
|
+
if (argv.feature) {
|
|
72
|
+
featureFiles.push(path.resolve(argv.feature));
|
|
81
73
|
} else if (configOptions.paths && configOptions.paths.length > 0) {
|
|
82
|
-
|
|
74
|
+
featureFiles.push(...configOptions.paths);
|
|
75
|
+
}
|
|
76
|
+
if (featureFiles.length > 0) {
|
|
77
|
+
cucumberArgs.push(...featureFiles);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
//
|
|
80
|
+
// Require default step definitions
|
|
81
|
+
const defaultStepsPath = path.resolve(
|
|
82
|
+
process.cwd(),
|
|
83
|
+
"node_modules",
|
|
84
|
+
"k6-cucumber-steps",
|
|
85
|
+
"step_definitions"
|
|
86
|
+
);
|
|
87
|
+
cucumberArgs.push("--require", defaultStepsPath);
|
|
88
|
+
|
|
89
|
+
// Also require additional custom step definitions from config, if any
|
|
90
|
+
if (configOptions.require && Array.isArray(configOptions.require)) {
|
|
91
|
+
for (const reqPath of configOptions.require) {
|
|
92
|
+
cucumberArgs.push("--require", reqPath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Determine base report name
|
|
86
97
|
const reportsDir = path.join(process.cwd(), "reports");
|
|
87
98
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
88
99
|
|
|
89
|
-
|
|
100
|
+
let baseReportName = "load-results";
|
|
101
|
+
if (featureFiles.length === 1) {
|
|
102
|
+
const nameFromFeature = path.basename(featureFiles[0], ".feature");
|
|
103
|
+
baseReportName = nameFromFeature || baseReportName;
|
|
104
|
+
} else if (featureFiles.length > 1) {
|
|
105
|
+
baseReportName = "multi-feature";
|
|
106
|
+
}
|
|
90
107
|
|
|
108
|
+
const shouldGenerateReports = argv.reporter || configOptions.reporter || false;
|
|
91
109
|
const shouldOverwrite =
|
|
92
110
|
argv.overwrite ||
|
|
93
111
|
process.env.K6_CUCUMBER_OVERWRITE === "true" ||
|
|
94
112
|
configOptions.overwrite === true;
|
|
95
113
|
|
|
96
|
-
|
|
97
|
-
let
|
|
114
|
+
let reportJsonPath = path.join(reportsDir, `${baseReportName}.json`);
|
|
115
|
+
let reportHtmlPath = path.join(reportsDir, `${baseReportName}.html`);
|
|
98
116
|
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
baseNames = configOptions.paths.map((p) => path.basename(p, path.extname(p)));
|
|
103
|
-
} else {
|
|
104
|
-
baseNames = ["load-results"];
|
|
117
|
+
if (!shouldOverwrite) {
|
|
118
|
+
reportJsonPath = path.join(reportsDir, `${baseReportName}-${timestamp}.json`);
|
|
119
|
+
reportHtmlPath = path.join(reportsDir, `${baseReportName}-${timestamp}.html`);
|
|
105
120
|
}
|
|
106
121
|
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
});
|
|
122
|
+
const formatInConfig =
|
|
123
|
+
Array.isArray(configOptions.format) && configOptions.format.length > 0;
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
if (shouldGenerateReports) {
|
|
125
|
+
if (shouldGenerateReports && !formatInConfig) {
|
|
124
126
|
fs.mkdirSync(reportsDir, { recursive: true });
|
|
125
|
-
|
|
126
|
-
cucumberArgs.push("--format",
|
|
127
|
-
|
|
128
|
-
reportPaths.forEach(({ json, html }) => {
|
|
129
|
-
cucumberArgs.push("--format", `json:${json}`);
|
|
130
|
-
cucumberArgs.push("--format", `html:${html}`);
|
|
131
|
-
});
|
|
127
|
+
cucumberArgs.push("--format", `summary`);
|
|
128
|
+
cucumberArgs.push("--format", `json:${reportJsonPath}`);
|
|
129
|
+
cucumberArgs.push("--format", `html:${reportHtmlPath}`);
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
console.log("š Reporter Enabled:", shouldGenerateReports);
|
|
135
|
-
console.log("š Overwrite Enabled:", shouldOverwrite);
|
|
136
|
-
|
|
137
132
|
console.log("\nā¶ļø Final arguments passed to cucumber-js:");
|
|
138
133
|
console.log(["npx", ...cucumberArgs].join(" ") + "\n");
|
|
139
134
|
|
|
@@ -143,9 +138,9 @@ const cucumberProcess = spawn("npx", cucumberArgs, {
|
|
|
143
138
|
...process.env,
|
|
144
139
|
K6_CUCUMBER_OVERWRITE: shouldOverwrite ? "true" : "false",
|
|
145
140
|
TAGS: tags,
|
|
146
|
-
FEATURE_PATH:
|
|
147
|
-
REPORT_JSON_PATH:
|
|
148
|
-
REPORT_HTML_PATH:
|
|
141
|
+
FEATURE_PATH: featureFiles.join(","),
|
|
142
|
+
REPORT_JSON_PATH: reportJsonPath,
|
|
143
|
+
REPORT_HTML_PATH: reportHtmlPath,
|
|
149
144
|
},
|
|
150
145
|
});
|
|
151
146
|
|
package/index.js
CHANGED
|
@@ -1,24 +1 @@
|
|
|
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
|
-
};
|
|
24
1
|
export * from "./step_definitions/load_test_steps.js";
|