k6-cucumber-steps 1.0.26 → 1.0.27

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/README.md CHANGED
@@ -7,7 +7,6 @@
7
7
  [![npm version](https://img.shields.io/npm/v/k6-cucumber-steps.svg)](https://www.npmjs.com/package/k6-cucumber-steps)
8
8
  [![npm downloads](https://img.shields.io/npm/dt/k6-cucumber-steps.svg)](https://www.npmjs.com/package/k6-cucumber-steps)
9
9
  [![license](https://img.shields.io/npm/l/k6-cucumber-steps)](https://github.com/qaPaschalE/k6-cucumber-steps/blob/main/LICENSE)
10
-
11
10
  [![Cucumber](https://img.shields.io/badge/built%20with-Cucumber-3178c6.svg)](https://cucumber.io/)
12
11
  [![Node.js](https://img.shields.io/badge/node-%3E=18-green.svg)](https://nodejs.org/)
13
12
  [![Sponsor](https://img.shields.io/github/sponsors/qaPaschalE?style=social)](https://github.com/sponsors/qaPaschalE)
@@ -8,15 +8,33 @@ const packageJson = require("../../package.json"); // Access package version
8
8
  * Generates a temporary k6 script file.
9
9
  * @param {string} scriptContent - The content of the k6 script.
10
10
  * @param {string} [scriptType='load'] - Type of script (e.g., 'load').
11
+ * @param {boolean} [overwrite=false] - Whether to overwrite the report file.
11
12
  * @returns {Promise<string>} - Path to the generated k6 script file.
12
13
  */
13
- const generateK6Script = async (scriptContent, scriptType = "load") => {
14
+ const generateK6Script = async (
15
+ scriptContent,
16
+ scriptType = "load",
17
+ overwrite = false
18
+ ) => {
14
19
  const tempDir = path.resolve(__dirname, "../../temp");
15
20
  const scriptName = `${scriptType}_script_${uuidv4()}.js`;
16
21
  const scriptPath = path.join(tempDir, scriptName);
17
- await fs.mkdir(tempDir, { recursive: true }); // Ensure temp directory exists
18
- await fs.writeFile(scriptPath, scriptContent, "utf8");
19
- return scriptPath;
22
+
23
+ try {
24
+ await fs.mkdir(tempDir, { recursive: true }); // Ensure temp directory exists
25
+
26
+ // Write the script content based on the overwrite flag
27
+ if (overwrite) {
28
+ await fs.writeFile(scriptPath, scriptContent, { flag: "w" }); // Overwrite mode
29
+ } else {
30
+ await fs.appendFile(scriptPath, scriptContent); // Append mode
31
+ }
32
+
33
+ return scriptPath;
34
+ } catch (error) {
35
+ console.error(`Error generating k6 script: ${error.message}`);
36
+ throw error;
37
+ }
20
38
  };
21
39
 
22
40
  /**
@@ -29,9 +47,10 @@ const delay = (ms) => new Promise((res) => setTimeout(res, ms));
29
47
  /**
30
48
  * Runs the k6 script with custom branding.
31
49
  * @param {string} scriptPath - Path to the k6 script file.
50
+ * @param {boolean} [overwrite=false] - Whether to overwrite the report file.
32
51
  * @returns {Promise<string>} - Standard output from k6 execution.
33
52
  */
34
- const runK6Script = async (scriptPath) => {
53
+ const runK6Script = async (scriptPath, overwrite = false) => {
35
54
  // ANSI escape codes for colors
36
55
  const chalkGreen = "\x1b[38;2;0;255;0m"; // Green
37
56
  const chalkYellow = "\x1b[38;2;255;255;0m"; // Yellow
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k6-cucumber-steps",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {