@dev-blinq/cucumber_client 1.0.1183-dev → 1.0.1185-dev

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,4 +1,4 @@
1
- import { existsSync, mkdirSync } from "fs";
1
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
2
2
  import logger from "../logger.js";
3
3
  import path from "path";
4
4
  import { scenarioResolution } from "./cucumber/feature.js";
@@ -13,6 +13,77 @@ import crypto from "crypto";
13
13
  //import debug from "debug";
14
14
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
15
15
 
16
+ // Initialize the editorLogs array to collect all logs
17
+ const editorLogs = [];
18
+
19
+ // Store original console methods
20
+ const originalConsoleLog = console.log;
21
+ const originalConsoleError = console.error;
22
+
23
+ // Store original process stdout and stderr write methods
24
+ const originalStdoutWrite = process.stdout.write;
25
+ const originalStderrWrite = process.stderr.write;
26
+
27
+ // Override console.log
28
+ console.log = function (...args) {
29
+ const logEntry = {
30
+ message: args.map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg))).join(" "),
31
+ };
32
+
33
+ editorLogs.push(logEntry);
34
+ originalConsoleLog.apply(console, args);
35
+ };
36
+
37
+ // Override console.error
38
+ console.error = function (...args) {
39
+ const logEntry = {
40
+ message: args.map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg))).join(" "),
41
+ };
42
+
43
+ editorLogs.push(logEntry);
44
+ originalConsoleError.apply(console, args);
45
+ };
46
+
47
+ // Override process.stdout.write
48
+ process.stdout.write = function (chunk, encoding, callback) {
49
+ const logEntry = {
50
+ message: chunk.toString(),
51
+ };
52
+
53
+ editorLogs.push(logEntry);
54
+ return originalStdoutWrite.apply(process.stdout, arguments);
55
+ };
56
+
57
+ // Override process.stderr.write
58
+ process.stderr.write = function (chunk, encoding, callback) {
59
+ const logEntry = {
60
+ message: chunk.toString(),
61
+ };
62
+
63
+ editorLogs.push(logEntry);
64
+ return originalStderrWrite.apply(process.stderr, arguments);
65
+ };
66
+
67
+ // Function to write logs to file
68
+ const writeLogsToFile = (filePath) => {
69
+ try {
70
+ const dirPath = path.dirname(filePath);
71
+
72
+ // Create directory if it doesn't exist
73
+ if (!existsSync(dirPath)) {
74
+ mkdirSync(dirPath, { recursive: true });
75
+ }
76
+
77
+ // Format logs as plain message on each line
78
+ const logText = editorLogs.map((log) => `${log.message}`).join("\n");
79
+
80
+ // Write logs to plain text file
81
+ writeFileSync(filePath, logText, { encoding: "utf8" });
82
+ } catch (error) {
83
+ logger.error(`Failed to write logs to file: ${error.message}`);
84
+ }
85
+ };
86
+
16
87
  //do something when app is closing
17
88
 
18
89
  const runCucumber = async (
@@ -93,7 +164,14 @@ const runCucumber = async (
93
164
  }
94
165
  return true;
95
166
  });
96
- process.on("exit", async () => await aiAgent.endScenario());
167
+ process.on("exit", async () => {
168
+ // Write logs to file before exiting
169
+ if (result.scenarioPath) {
170
+ const logsFilePath = path.join(result.scenarioPath, "editorLogs.log");
171
+ writeLogsToFile(logsFilePath);
172
+ }
173
+ await aiAgent.endScenario();
174
+ });
97
175
  const context = {};
98
176
  result.context = context;
99
177
  if (process.env.E2E === "true") {
@@ -105,6 +183,9 @@ const runCucumber = async (
105
183
  envFile = await aiAgent.initProjectAndEnvironment(context);
106
184
  } catch (e) {
107
185
  logger.error(e.message);
186
+ // Write logs to file before exiting due to error
187
+ const logsFilePath = path.join(result.scenarioPath, "editorLogs.log");
188
+ writeLogsToFile(logsFilePath);
108
189
  if (exit) {
109
190
  process.exit(1);
110
191
  }
@@ -118,6 +199,9 @@ const runCucumber = async (
118
199
  }
119
200
  if (!existsSync(fullFeatureFilePath)) {
120
201
  logger.error("Feature file not found: " + fullFeatureFilePath);
202
+ // Write logs to file before exiting due to error
203
+ const logsFilePath = path.join(result.scenarioPath, "editorLogs.log");
204
+ writeLogsToFile(logsFilePath);
121
205
  if (exit) {
122
206
  process.exit(1);
123
207
  }
@@ -128,6 +212,9 @@ const runCucumber = async (
128
212
  feature = await scenarioResolution(fullFeatureFilePath);
129
213
  } catch (e) {
130
214
  logger.error("Error parsing feature file: " + fullFeatureFilePath);
215
+ // Write logs to file before exiting due to error
216
+ const logsFilePath = path.join(result.scenarioPath, "editorLogs.log");
217
+ writeLogsToFile(logsFilePath);
131
218
  if (exit) {
132
219
  process.exit(1);
133
220
  }
@@ -136,6 +223,9 @@ const runCucumber = async (
136
223
  const scenario = feature.getScenario(scenarioName);
137
224
  if (!scenario) {
138
225
  logger.error("Scenario not found: " + scenarioName);
226
+ // Write logs to file before exiting due to error
227
+ const logsFilePath = path.join(result.scenarioPath, "editorLogs.log");
228
+ writeLogsToFile(logsFilePath);
139
229
  if (exit) {
140
230
  process.exit(1);
141
231
  }
@@ -283,6 +373,9 @@ const runCucumber = async (
283
373
  ) {
284
374
  aiAgent.evaluateScenario();
285
375
  }
376
+ // Write logs to file on successful completion
377
+ const logsFilePath = path.join(scenarioPath, "editorLogs.log");
378
+ writeLogsToFile(logsFilePath);
286
379
  await aiAgent.endScenario();
287
380
  } catch (e) {
288
381
  if (reconnect) {
@@ -303,7 +396,11 @@ const runCucumber = async (
303
396
  logger.error(e.stack);
304
397
  message = e.message + "\n" + e.stack;
305
398
  }
399
+ // Write logs to file on error
400
+ const logsFilePath = path.join(result.scenarioPath, "editorLogs.log");
401
+ writeLogsToFile(logsFilePath);
306
402
  await aiAgent.endScenario();
403
+
307
404
  if (exit) {
308
405
  process.exit(1);
309
406
  }
@@ -316,4 +413,5 @@ const runCucumber = async (
316
413
  return result;
317
414
  }
318
415
  };
319
- export { runCucumber };
416
+
417
+ export { runCucumber, editorLogs, writeLogsToFile };
@@ -215,7 +215,12 @@ class ScenarioReport {
215
215
  } else {
216
216
  const report = getJsonReport(this);
217
217
  fs.writeFileSync(path.join(this.scenarioPath, "scenario.json"), JSON.stringify(report, null, 2));
218
- const fileUris = [...this.getFileUrisScreenShotDir(this.scenarioPath), "scenario.json", "network.json"];
218
+ const fileUris = [
219
+ ...this.getFileUrisScreenShotDir(this.scenarioPath),
220
+ "scenario.json",
221
+ "network.json",
222
+ "editorLogs.log",
223
+ ];
219
224
  const networkJsonPath = path.join(this.scenarioPath, "network.json");
220
225
  if (!fs.existsSync(networkJsonPath)) {
221
226
  fs.writeFileSync(networkJsonPath, JSON.stringify({}), "utf-8");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1183-dev",
3
+ "version": "1.0.1185-dev",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "@babel/traverse": "^7.27.1",
27
27
  "@babel/types": "^7.27.1",
28
28
  "@cucumber/tag-expressions": "^6.1.1",
29
- "@dev-blinq/cucumber-js": "1.0.171-dev",
29
+ "@dev-blinq/cucumber-js": "1.0.172-dev",
30
30
  "@faker-js/faker": "^8.1.0",
31
31
  "automation_model": "1.0.717-dev",
32
32
  "axios": "^1.7.4",