@dev-blinq/cucumber-js 1.0.128-dev → 1.0.128-stage

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.
Files changed (52) hide show
  1. package/bin/cucumber.ts +1 -0
  2. package/bin/download-install.js +22 -2
  3. package/lib/api/console_logger.js.map +1 -1
  4. package/lib/cli/run.js +1 -0
  5. package/lib/cli/run.js.map +1 -1
  6. package/lib/cli/validate_node_engine_version.js +3 -1
  7. package/lib/cli/validate_node_engine_version.js.map +1 -1
  8. package/lib/configuration/axios_client.js +1 -1
  9. package/lib/configuration/axios_client.js.map +1 -1
  10. package/lib/formatter/api.js +16 -5
  11. package/lib/formatter/api.js.map +1 -1
  12. package/lib/formatter/builder.js +1 -3
  13. package/lib/formatter/builder.js.map +1 -1
  14. package/lib/formatter/bvt_analysis_formatter.d.ts +14 -1
  15. package/lib/formatter/bvt_analysis_formatter.js +221 -59
  16. package/lib/formatter/bvt_analysis_formatter.js.map +1 -1
  17. package/lib/formatter/feature_data_format.js +22 -8
  18. package/lib/formatter/feature_data_format.js.map +1 -1
  19. package/lib/formatter/helpers/constants.d.ts +63 -0
  20. package/lib/formatter/helpers/constants.js +73 -0
  21. package/lib/formatter/helpers/constants.js.map +1 -0
  22. package/lib/formatter/helpers/report_generator.d.ts +23 -3
  23. package/lib/formatter/helpers/report_generator.js +342 -27
  24. package/lib/formatter/helpers/report_generator.js.map +1 -1
  25. package/lib/formatter/helpers/test_case_attempt_formatter.js +1 -1
  26. package/lib/formatter/helpers/test_case_attempt_formatter.js.map +1 -1
  27. package/lib/formatter/helpers/test_case_attempt_parser.js.map +1 -1
  28. package/lib/formatter/helpers/upload_serivce.d.ts +22 -2
  29. package/lib/formatter/helpers/upload_serivce.js +222 -34
  30. package/lib/formatter/helpers/upload_serivce.js.map +1 -1
  31. package/lib/formatter/helpers/uploader.js +6 -2
  32. package/lib/formatter/helpers/uploader.js.map +1 -1
  33. package/lib/formatter/progress_formatter.d.ts +2 -1
  34. package/lib/formatter/progress_formatter.js.map +1 -1
  35. package/lib/formatter/snippets_formatter.js.map +1 -1
  36. package/lib/formatter/summary_formatter.js +4 -0
  37. package/lib/formatter/summary_formatter.js.map +1 -1
  38. package/lib/formatter/usage_formatter.js.map +1 -1
  39. package/lib/formatter/usage_json_formatter.js.map +1 -1
  40. package/lib/models/definition.js.map +1 -1
  41. package/lib/pickle_filter.d.ts +3 -2
  42. package/lib/pickle_filter.js.map +1 -1
  43. package/lib/runtime/test_case_runner.d.ts +2 -0
  44. package/lib/runtime/test_case_runner.js +17 -1
  45. package/lib/runtime/test_case_runner.js.map +1 -1
  46. package/lib/support_code_library_builder/world.js.map +1 -1
  47. package/lib/uncaught_exception_manager.d.ts +1 -1
  48. package/lib/uncaught_exception_manager.js.map +1 -1
  49. package/lib/version.d.ts +1 -1
  50. package/lib/version.js +1 -1
  51. package/lib/version.js.map +1 -1
  52. package/package.json +7 -3
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.logReportLink = void 0;
6
+ exports.createNewTestCase = exports.postUploadReportEvent = exports.logReportLink = exports.globalReportLink = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const fs_1 = require("fs");
9
9
  const promises_1 = require("fs/promises");
@@ -16,29 +16,53 @@ const uploader_1 = __importDefault(require("./helpers/uploader"));
16
16
  const os_1 = __importDefault(require("os"));
17
17
  const api_1 = require("./api");
18
18
  const summary_formatter_1 = __importDefault(require("./summary_formatter"));
19
+ const constants_1 = require("./helpers/constants");
20
+ const axios_client_1 = require("../configuration/axios_client");
21
+ const util_1 = require("util");
22
+ const child_process_2 = require("child_process");
19
23
  //User token
20
24
  const TOKEN = process.env.TOKEN;
25
+ exports.globalReportLink = '';
21
26
  class BVTAnalysisFormatter extends _1.default {
22
27
  constructor(options) {
23
28
  super(options);
24
29
  this.reportGenerator = new report_generator_1.default();
25
30
  this.uploader = new uploader_1.default(this.reportGenerator);
26
31
  this.exit = false;
32
+ this.rootCauseArray = [];
27
33
  this.summaryFormatter = new summary_formatter_1.default(options);
34
+ BVTAnalysisFormatter.reportGenerator = this.reportGenerator;
35
+ this.rootCauseArray = [];
36
+ this.failedStepsIndex = [];
37
+ BVTAnalysisFormatter.reRunFailedStepsIndex = process.env.RERUN
38
+ ? JSON.parse(process.env.RERUN)
39
+ : null;
28
40
  if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {
29
41
  throw new Error('TOKEN must be set');
30
42
  }
31
- options.eventBroadcaster.on('envelope', async (envelope) => {
43
+ this.sendEvent(constants_1.ActionEvents.cli_run_tests);
44
+ options.eventBroadcaster.on('envelope', async (envelope, data) => {
45
+ if ((0, value_checker_1.doesHaveValue)(envelope.testCaseFinished) && data) {
46
+ const { rootCause, report } = data;
47
+ if (!rootCause.status) {
48
+ console.error(`Root cause: ${rootCause.failClass}\n, ${rootCause.analysis}\nfailing step: ${rootCause.failedStep}`);
49
+ this.rootCauseArray.push({ rootCause, report });
50
+ this.failedStepsIndex.push({
51
+ testCaseId: report.id,
52
+ failedStepIndex: rootCause.failedStep,
53
+ });
54
+ }
55
+ return;
56
+ }
32
57
  await this.reportGenerator.handleMessage(envelope);
33
58
  if ((0, value_checker_1.doesHaveValue)(envelope.meta) &&
34
59
  (0, value_checker_1.doesHaveValue)(envelope.meta.runName)) {
35
60
  this.runName = envelope.meta.runName;
36
61
  }
37
62
  if ((0, value_checker_1.doesHaveValue)(envelope.testRunFinished)) {
38
- const report = this.reportGenerator.getReport();
39
63
  this.START = Date.now();
40
64
  if (process.env.BVT_FORMATTER === 'ANALYSIS') {
41
- await this.analyzeReport(report);
65
+ await this.analyzeReport();
42
66
  }
43
67
  else {
44
68
  // await this.uploadReport(report)
@@ -47,6 +71,20 @@ class BVTAnalysisFormatter extends _1.default {
47
71
  }
48
72
  });
49
73
  }
74
+ sendEvent(event) {
75
+ axios_client_1.axiosClient
76
+ .post(`${constants_1.SERVICES_URI.STORAGE}/event`, {
77
+ event,
78
+ }, {
79
+ headers: {
80
+ Authorization: `Bearer ${TOKEN}`,
81
+ 'x-source': 'cucumber_js',
82
+ },
83
+ })
84
+ .catch((err) => {
85
+ // Error with events, ignoring
86
+ });
87
+ }
50
88
  async uploadReport(report) {
51
89
  const uploadSuccessful = await this.uploadFinalReport(report);
52
90
  if (uploadSuccessful && report.result.status !== 'FAILED') {
@@ -77,10 +115,10 @@ class BVTAnalysisFormatter extends _1.default {
77
115
  }, 100); // check every 100ms
78
116
  });
79
117
  }
80
- async analyzeReport(report) {
81
- if (report.result.status === 'PASSED' ||
118
+ async analyzeReport() {
119
+ if (this.rootCauseArray.length === 0 ||
82
120
  process.env.NO_RETRAIN === 'false') {
83
- if (report.result.status === 'PASSED') {
121
+ if (this.rootCauseArray.length === 0) {
84
122
  this.log('No test failed. No need to retrain\n');
85
123
  }
86
124
  if (process.env.NO_RETRAIN === 'false') {
@@ -93,61 +131,52 @@ class BVTAnalysisFormatter extends _1.default {
93
131
  }
94
132
  //checking if the type of report.result is JsonResultFailed or not
95
133
  this.log('Some tests failed, starting the retraining...\n');
96
- if (!('startTime' in report.result) || !('endTime' in report.result)) {
97
- this.log('Unknown error occured,not retraining\n');
98
- return;
99
- }
100
- await this.processTestCases(report);
134
+ await this.processTestCases();
101
135
  if (this.reportGenerator.getReport().result.status === 'FAILED') {
102
136
  process.exit(1);
103
137
  }
104
138
  process.exit(0);
105
139
  }
106
- async processTestCases(report) {
107
- const finalTestCases = [];
108
- for (const testCase of report.testCases) {
109
- const modifiedTestCase = await this.processTestCase(testCase, report);
110
- finalTestCases.push(modifiedTestCase);
140
+ async processTestCases() {
141
+ for (const { rootCause, report } of this.rootCauseArray) {
142
+ await this.processTestCase(rootCause, report);
111
143
  }
112
- const finalResult = finalTestCases.some((tc) => tc.result.status !== 'PASSED')
113
- ? report.result
114
- : {
115
- ...report.result,
116
- status: 'PASSED',
117
- };
118
- return {
119
- result: finalResult,
120
- testCases: finalTestCases,
121
- env: report.env,
122
- };
123
144
  }
124
- async processTestCase(testCase, report) {
125
- if (testCase.result.status === 'PASSED') {
126
- return testCase;
145
+ async processTestCase(rootCause, report) {
146
+ const failedTestSteps = rootCause.failedStep;
147
+ if (BVTAnalysisFormatter.reRunFailedStepsIndex &&
148
+ BVTAnalysisFormatter.reRunFailedStepsIndex.length > 0) {
149
+ const previousRun = BVTAnalysisFormatter.reRunFailedStepsIndex[0];
150
+ if (previousRun.failedStepIndex === failedTestSteps) {
151
+ console.log('Same step has failed again, skipping retraining');
152
+ BVTAnalysisFormatter.reRunFailedStepsIndex.shift();
153
+ return;
154
+ }
155
+ BVTAnalysisFormatter.reRunFailedStepsIndex.shift();
127
156
  }
128
- const failedTestSteps = testCase.steps
129
- .map((step, i) => (step.result.status === 'FAILED' ? i : null))
130
- .filter((i) => i !== null);
131
- const retrainStats = await this.retrain(failedTestSteps, testCase);
132
- if (!retrainStats) {
133
- return testCase;
157
+ if (process.env.RERUN) {
158
+ await this.uploader.modifyTestCase({
159
+ ...report,
160
+ });
161
+ return;
134
162
  }
135
- if (retrainStats.result.status === 'PASSED') {
163
+ const retrainStats = await this.retrain(failedTestSteps, report);
164
+ if (retrainStats) {
136
165
  await this.uploader.modifyTestCase({
137
- ...testCase,
166
+ ...report,
138
167
  retrainStats,
139
168
  });
140
169
  }
141
- return {
142
- ...testCase,
143
- retrainStats,
144
- };
170
+ else {
171
+ this.log(`No stats found retraining...`);
172
+ }
173
+ await this.rerun(report);
145
174
  }
146
175
  async uploadFinalReport(finalReport) {
147
176
  let success = true;
148
177
  try {
149
178
  const { projectId, runId } = await this.uploader.uploadRun(finalReport, this.runName);
150
- logReportLink(runId, projectId);
179
+ logReportLink(runId, projectId, finalReport.result);
151
180
  }
152
181
  catch (err) {
153
182
  this.log('Error uploading report\n');
@@ -176,6 +205,45 @@ class BVTAnalysisFormatter extends _1.default {
176
205
  }
177
206
  return await this.call_cucumber_client(failedTestCases, testCase);
178
207
  }
208
+ async rerun(report) {
209
+ await new Promise((resolve) => {
210
+ // Default to system Node.js
211
+ const node_path = process.execPath;
212
+ // Use bundled Node if running from recorder app on macOS or Windows
213
+ const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true';
214
+ const args = [
215
+ path_1.default.join(process.cwd(), 'node_modules', '@dev-blinq', 'cucumber-js', 'bin', 'cucumber.js'),
216
+ '--name',
217
+ `^${report.scenarioName}$`,
218
+ '--exit',
219
+ '--format',
220
+ 'bvt',
221
+ '--run-name',
222
+ `${report.scenarioName}@debug`,
223
+ path_1.default.join(process.cwd(), report.uri),
224
+ ];
225
+ const envVars = {
226
+ ...process.env,
227
+ RERUN: JSON.stringify(this.failedStepsIndex),
228
+ };
229
+ // Inject Electron node env only if using electron's bundled node
230
+ if (isFromRecorderApp) {
231
+ envVars.ELECTRON_RUN_AS_NODE = '1';
232
+ }
233
+ const cucumberJSChildProcess = (0, child_process_1.spawn)(node_path, args, {
234
+ env: envVars,
235
+ });
236
+ cucumberJSChildProcess.stdout.on('data', (data) => {
237
+ console.log(data.toString());
238
+ });
239
+ cucumberJSChildProcess.stderr.on('data', (data) => {
240
+ console.error(data.toString());
241
+ });
242
+ cucumberJSChildProcess.on('close', () => {
243
+ resolve();
244
+ });
245
+ });
246
+ }
179
247
  async call_cucumber_client(stepsToRetrain, testCase) {
180
248
  return new Promise((resolve, reject) => {
181
249
  const cucumber_client_path = path_1.default.resolve(process.cwd(), 'node_modules', '@dev-blinq', 'cucumber_client', 'bin', 'client', 'cucumber.js');
@@ -184,7 +252,7 @@ class BVTAnalysisFormatter extends _1.default {
184
252
  path_1.default.join(process.cwd(), testCase.uri),
185
253
  `${testCase.scenarioName}`,
186
254
  'undefined',
187
- `${stepsToRetrain.join(',')}`,
255
+ `${stepsToRetrain},`,
188
256
  ];
189
257
  if (process.env.BLINQ_ENV) {
190
258
  args.push(`--env=${process.env.BLINQ_ENV}`);
@@ -197,13 +265,24 @@ class BVTAnalysisFormatter extends _1.default {
197
265
  (0, tmp_1.tmpName)(async (err, name) => {
198
266
  const tempFile = path_1.default.join(this.getAppDataDir(), 'blinq.io', '.temp', path_1.default.basename(name));
199
267
  console.log('File path: ', tempFile);
268
+ if (!(0, fs_1.existsSync)(path_1.default.dirname(tempFile))) {
269
+ await (0, promises_1.mkdir)(path_1.default.dirname(tempFile), { recursive: true });
270
+ }
200
271
  await (0, promises_1.writeFile)(tempFile, '', 'utf-8');
201
272
  args.push(`--temp-file=${tempFile}`);
202
- const cucumberClient = (0, child_process_1.spawn)('node', [cucumber_client_path, ...args], {
203
- env: {
204
- ...process.env,
205
- TEMP_FILE_PATH: tempFile,
206
- },
273
+ // Determine node path
274
+ const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true';
275
+ const node_path = process.execPath;
276
+ const envVars = {
277
+ ...process.env,
278
+ TEMP_FILE_PATH: tempFile,
279
+ TRACE: undefined,
280
+ };
281
+ if (isFromRecorderApp) {
282
+ envVars.ELECTRON_RUN_AS_NODE = '1';
283
+ }
284
+ const cucumberClient = (0, child_process_1.spawn)(node_path, [cucumber_client_path, ...args], {
285
+ env: envVars,
207
286
  });
208
287
  cucumberClient.stdout.on('data', (data) => {
209
288
  console.log(data.toString());
@@ -212,14 +291,25 @@ class BVTAnalysisFormatter extends _1.default {
212
291
  console.error(data.toString());
213
292
  });
214
293
  cucumberClient.on('close', async (code) => {
215
- if (code === 0) {
216
- const reportData = (0, fs_1.readFileSync)(tempFile, 'utf-8');
217
- const retrainStats = JSON.parse(reportData);
218
- await (0, promises_1.unlink)(tempFile);
219
- resolve(retrainStats);
294
+ try {
295
+ if (code === 0) {
296
+ const reportData = (0, fs_1.readFileSync)(tempFile, 'utf-8');
297
+ const retrainStats = JSON.parse(reportData);
298
+ await (0, promises_1.unlink)(tempFile);
299
+ resolve(retrainStats);
300
+ }
301
+ else {
302
+ this.log('Error retraining\n');
303
+ const reportData = (0, fs_1.readFileSync)(tempFile, 'utf-8');
304
+ const retrainStats = JSON.parse(reportData);
305
+ await (0, promises_1.unlink)(tempFile);
306
+ resolve(retrainStats);
307
+ }
220
308
  }
221
- else {
222
- this.log('Error retraining\n');
309
+ catch (e) {
310
+ const message = e.message;
311
+ const stack = e.stack;
312
+ this.log(`Error occured while reading scenario report:${message}\n${stack}`);
223
313
  resolve(null);
224
314
  }
225
315
  });
@@ -246,7 +336,7 @@ class BVTAnalysisFormatter extends _1.default {
246
336
  }
247
337
  }
248
338
  exports.default = BVTAnalysisFormatter;
249
- function logReportLink(runId, projectId) {
339
+ function logReportLink(runId, projectId, status) {
250
340
  let reportLinkBaseUrl = 'https://app.blinq.io';
251
341
  if (process.env.NODE_ENV_BLINQ === 'local') {
252
342
  reportLinkBaseUrl = 'http://localhost:3000';
@@ -257,8 +347,80 @@ function logReportLink(runId, projectId) {
257
347
  else if (process.env.NODE_ENV_BLINQ === 'stage') {
258
348
  reportLinkBaseUrl = 'https://stage.app.blinq.io';
259
349
  }
350
+ else if (process.env.NODE_ENV_BLINQ === 'prod') {
351
+ reportLinkBaseUrl = 'https://app.blinq.io';
352
+ }
353
+ else if (!process.env.NODE_ENV_BLINQ) {
354
+ reportLinkBaseUrl = 'https://app.blinq.io';
355
+ }
356
+ else {
357
+ reportLinkBaseUrl = process.env.NODE_ENV_BLINQ.replace('api', 'app');
358
+ }
260
359
  const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`;
261
- console.log(`Report link: ${reportLink}\n`);
360
+ exports.globalReportLink = reportLink;
361
+ try {
362
+ publishReportLinkToGuacServer(reportLink, status.status === 'PASSED');
363
+ }
364
+ catch (err) {
365
+ // Error with events, ignoring
366
+ }
367
+ return reportLink;
262
368
  }
263
369
  exports.logReportLink = logReportLink;
370
+ function publishReportLinkToGuacServer(reportLink, result) {
371
+ if ((0, fs_1.existsSync)('/tmp/report_publish.sh')) {
372
+ const execAsync = (0, util_1.promisify)(child_process_2.exec);
373
+ execAsync('sh /tmp/report_publish.sh ' + reportLink + ' ' + result);
374
+ }
375
+ }
376
+ async function postUploadReportEvent(projectId, accessToken) {
377
+ try {
378
+ await axios_client_1.axiosClient.post(`${constants_1.SERVICES_URI.STORAGE}/event`, { event: constants_1.ActionEvents.upload_report }, {
379
+ headers: {
380
+ Authorization: 'Bearer ' + accessToken,
381
+ 'x-source': 'cucumber_js',
382
+ 'x-bvt-project-id': projectId,
383
+ },
384
+ });
385
+ }
386
+ catch (_a) { }
387
+ }
388
+ exports.postUploadReportEvent = postUploadReportEvent;
389
+ async function createNewTestCase(payload, runsApiBaseURL, accessToken) {
390
+ var _a, _b, _c, _d;
391
+ const jsonSizeKB = Buffer.byteLength(JSON.stringify(payload)) / 1024;
392
+ if (jsonSizeKB > 10240) {
393
+ // 10 MB
394
+ console.warn(`⚠️ Payload exceeds recommended size of 10MB: ${jsonSizeKB} KB`);
395
+ }
396
+ const MAX_RETRIES = 3;
397
+ const RETRY_DELAY_MS = 1000;
398
+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
399
+ const start = Date.now();
400
+ try {
401
+ const { data } = await axios_client_1.axiosClient.post(`${runsApiBaseURL}/cucumber-runs/createNewTestCase`, payload, {
402
+ headers: {
403
+ Authorization: 'Bearer ' + accessToken,
404
+ 'x-source': 'cucumber_js',
405
+ },
406
+ });
407
+ return data;
408
+ }
409
+ catch (e) {
410
+ const isLastAttempt = attempt === MAX_RETRIES;
411
+ const errInfo = {
412
+ attempt,
413
+ message: e === null || e === void 0 ? void 0 : e.message,
414
+ status: (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status,
415
+ responseSnippet: (_d = (_c = (_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.toString()) === null || _d === void 0 ? void 0 : _d.slice(0, 300),
416
+ durationMs: Date.now() - start,
417
+ };
418
+ console.error('🟥 Failed to POST /createNewTestCase:', JSON.stringify(errInfo, null, 2));
419
+ if (isLastAttempt)
420
+ throw e;
421
+ await new Promise((r) => setTimeout(r, RETRY_DELAY_MS * attempt));
422
+ }
423
+ }
424
+ }
425
+ exports.createNewTestCase = createNewTestCase;
264
426
  //# sourceMappingURL=bvt_analysis_formatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bvt_analysis_formatter.js","sourceRoot":"","sources":["../../src/formatter/bvt_analysis_formatter.ts"],"names":[],"mappings":";;;;;;AACA,iDAAqC;AACrC,2BAA4D;AAC5D,0CAAsD;AACtD,gDAAuB;AACvB,6BAA6B;AAC7B,yCAAgD;AAChD,oDAAgD;AAChD,kFAKmC;AACnC,kEAA+C;AAC/C,4CAAmB;AACnB,+BAA6C;AAC7C,4EAAkD;AAClD,YAAY;AACZ,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;AAQ/B,MAAqB,oBAAqB,SAAQ,UAAS;IAQzD,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QARR,oBAAe,GAAG,IAAI,0BAAe,EAAE,CAAA;QACvC,aAAQ,GAAG,IAAI,kBAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACnD,SAAI,GAAG,KAAK,CAAA;QAOlB,IAAI,CAAC,gBAAgB,GAAG,IAAI,2BAAgB,CAAC,OAAO,CAAC,CAAA;QACrD,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,UAAU,EAAE;YACtD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;SACrC;QACD,OAAO,CAAC,gBAAgB,CAAC,EAAE,CACzB,UAAU,EACV,KAAK,EAAE,QAAiC,EAAE,EAAE;YAC1C,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;YAClD,IACE,IAAA,6BAAa,EAAC,QAAQ,CAAC,IAAI,CAAC;gBAC5B,IAAA,6BAAa,EAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EACpC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BAAiB,GAAG,0BAA0B,CAAA;KAC/C;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO,EAAE;QACjD,iBAAiB,GAAG,4BAA4B,CAAA;KACjD;IACD,MAAM,UAAU,GAAG,GAAG,iBAAiB,IAAI,SAAS,eAAe,KAAK,EAAE,CAAA;IAC1E,OAAO,CAAC,GAAG,CAAC,gBAAgB,UAAU,IAAI,CAAC,CAAA;AAC7C,CAAC;AAXD,sCAWC","sourcesContent":["import { Envelope, Meta } from '@cucumber/messages'\nimport { spawn } from 'child_process'\nimport { readFileSync, existsSync, writeFileSync } from 'fs'\nimport { mkdir, unlink, writeFile } from 'fs/promises'\nimport path from 'path'\nimport { tmpName } from 'tmp'\nimport Formatter, { IFormatterOptions } from '.'\nimport { doesHaveValue } from '../value_checker'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n JsonTestResult,\n RetrainStats,\n} from './helpers/report_generator'\nimport ReportUploader from './helpers/uploader'\nimport os from 'os'\nimport { getProjectByAccessKey } from './api'\nimport SummaryFormatter from './summary_formatter'\n//User token\nconst TOKEN = process.env.TOKEN\ninterface MetaMessage extends Meta {\n runName: string\n}\n\ninterface EnvelopeWithMetaMessage extends Envelope {\n meta: MetaMessage\n}\nexport default class BVTAnalysisFormatter extends Formatter {\n private reportGenerator = new ReportGenerator()\n private uploader = new ReportUploader(this.reportGenerator)\n private exit = false\n private START: number\n private runName: string\n private summaryFormatter: SummaryFormatter\n\n constructor(options: IFormatterOptions) {\n super(options)\n this.summaryFormatter = new SummaryFormatter(options)\n if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {\n throw new Error('TOKEN must be set')\n }\n options.eventBroadcaster.on(\n 'envelope',\n async (envelope: EnvelopeWithMetaMessage) => {\n await this.reportGenerator.handleMessage(envelope)\n if (\n doesHaveValue(envelope.meta) &&\n doesHaveValue(envelope.meta.runName)\n ) {\n this.runName = envelope.meta.runName\n }\n if (doesHaveValue(envelope.testRunFinished)) {\n const report = this.reportGenerator.getReport()\n this.START = Date.now()\n if (process.env.BVT_FORMATTER === 'ANALYSIS') {\n await this.analyzeReport(report)\n } else {\n // await this.uploadReport(report)\n }\n this.exit = true\n }\n }\n )\n }\n\n private async uploadReport(report: JsonReport) {\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful && report.result.status !== 'FAILED') {\n process.exit(0)\n }\n process.exit(1)\n }\n\n async finished(): Promise<any> {\n await new Promise((resolve) => {\n const checkInterval = setInterval(() => {\n let anyRem\n if (process.env.UPLOADING_TEST_CASE) {\n anyRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n } else {\n anyRem = undefined\n }\n\n if (this.exit && (!anyRem || anyRem.length === 0)) {\n // clearInterval(checkInterval)\n // resolve(null)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n } else {\n process.exit(0)\n }\n }\n }, 100) // check every 100ms\n })\n }\n private async analyzeReport(report: JsonReport) {\n if (\n report.result.status === 'PASSED' ||\n process.env.NO_RETRAIN === 'false'\n ) {\n if (report.result.status === 'PASSED') {\n this.log('No test failed. No need to retrain\\n')\n }\n if (process.env.NO_RETRAIN === 'false') {\n this.log(\n 'Retraining is skipped since the failed step contains an API request\\n'\n )\n }\n // const uploadSuccessful = await this.uploadFinalReport(report)\n // process.exit(0)\n this.exit = true\n return\n }\n\n //checking if the type of report.result is JsonResultFailed or not\n this.log('Some tests failed, starting the retraining...\\n')\n if (!('startTime' in report.result) || !('endTime' in report.result)) {\n this.log('Unknown error occured,not retraining\\n')\n return\n }\n await this.processTestCases(report)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n }\n process.exit(0)\n }\n private async processTestCases(report: JsonReport): Promise<JsonReport> {\n const finalTestCases = []\n for (const testCase of report.testCases) {\n const modifiedTestCase = await this.processTestCase(testCase, report)\n\n finalTestCases.push(modifiedTestCase)\n }\n const finalResult = finalTestCases.some(\n (tc) => tc.result.status !== 'PASSED'\n )\n ? report.result\n : ({\n ...report.result,\n status: 'PASSED',\n } as JsonTestResult)\n return {\n result: finalResult,\n testCases: finalTestCases,\n env: report.env,\n }\n }\n private async processTestCase(\n testCase: JsonTestProgress,\n report: JsonReport\n ): Promise<JsonTestProgress> {\n if (testCase.result.status === 'PASSED') {\n return testCase\n }\n const failedTestSteps = testCase.steps\n .map((step, i) => (step.result.status === 'FAILED' ? i : null))\n .filter((i) => i !== null)\n const retrainStats = await this.retrain(failedTestSteps, testCase)\n\n if (!retrainStats) {\n return testCase\n }\n if (retrainStats.result.status === 'PASSED') {\n await this.uploader.modifyTestCase({\n ...testCase,\n retrainStats,\n })\n }\n\n return {\n ...testCase,\n retrainStats,\n }\n }\n\n private async uploadFinalReport(finalReport: JsonReport) {\n let success = true\n try {\n const { projectId, runId } = await this.uploader.uploadRun(\n finalReport,\n this.runName\n )\n logReportLink(runId, projectId)\n } catch (err) {\n this.log('Error uploading report\\n')\n if ('stack' in err) {\n this.log(err.stack)\n }\n success = false\n } finally {\n try {\n writeFileSync(\n path.join(this.reportGenerator.reportFolder, 'report.json'),\n JSON.stringify(finalReport, null, 2),\n 'utf-8'\n )\n } catch (e) {\n console.error('failed to write report.json to local disk')\n }\n }\n\n //this.log(JSON.stringify(finalReport, null, 2))\n return success\n }\n private async retrain(\n failedTestCases: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n const data = await getProjectByAccessKey(TOKEN)\n const currentTimestampInSeconds = Math.floor(Date.now() / 1000)\n if (data.project.expriration_date < currentTimestampInSeconds) {\n console.log(\n 'Warning: Your project has expired, retraining is restricted. Please contact sales.'\n )\n process.exit(1)\n }\n return await this.call_cucumber_client(failedTestCases, testCase)\n }\n\n private async call_cucumber_client(\n stepsToRetrain: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n return new Promise((resolve, reject) => {\n const cucumber_client_path = path.resolve(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber_client',\n 'bin',\n 'client',\n 'cucumber.js'\n )\n\n const args: string[] = [\n process.cwd(),\n path.join(process.cwd(), testCase.uri),\n `${testCase.scenarioName}`,\n 'undefined',\n `${stepsToRetrain.join(',')}`,\n ]\n\n if (process.env.BLINQ_ENV) {\n args.push(`--env=${process.env.BLINQ_ENV}`)\n }\n\n if (!existsSync(path.join(this.getAppDataDir(), 'blinq.io', '.temp'))) {\n mkdir(path.join(this.getAppDataDir(), 'blinq.io', '.temp'), {\n recursive: true,\n })\n }\n\n tmpName(async (err, name) => {\n const tempFile = path.join(\n this.getAppDataDir(),\n 'blinq.io',\n '.temp',\n path.basename(name)\n )\n console.log('File path: ', tempFile)\n await writeFile(tempFile, '', 'utf-8')\n\n args.push(`--temp-file=${tempFile}`)\n const cucumberClient = spawn('node', [cucumber_client_path, ...args], {\n env: {\n ...process.env,\n TEMP_FILE_PATH: tempFile,\n },\n })\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', async (code) => {\n if (code === 0) {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } else {\n this.log('Error retraining\\n')\n resolve(null)\n }\n })\n })\n })\n }\n\n private getAppDataDir() {\n if (process.env.BLINQ_APPDATA_DIR) {\n return process.env.BLINQ_APPDATA_DIR\n }\n\n let appDataDir: string\n\n switch (process.platform) {\n case 'win32':\n appDataDir = process.env.APPDATA!\n break\n case 'darwin':\n appDataDir = path.join(os.homedir(), 'Library', 'Application Support')\n break\n default:\n appDataDir = path.join(os.homedir(), '.config')\n break\n }\n return appDataDir\n }\n}\n\nexport function logReportLink(runId: string, projectId: string) {\n let reportLinkBaseUrl = 'https://app.blinq.io'\n if (process.env.NODE_ENV_BLINQ === 'local') {\n reportLinkBaseUrl = 'http://localhost:3000'\n } else if (process.env.NODE_ENV_BLINQ === 'dev') {\n reportLinkBaseUrl = 'https://dev.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'stage') {\n reportLinkBaseUrl = 'https://stage.app.blinq.io'\n }\n const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`\n console.log(`Report link: ${reportLink}\\n`)\n}\n"]}
1
+ {"version":3,"file":"bvt_analysis_formatter.js","sourceRoot":"","sources":["../../src/formatter/bvt_analysis_formatter.ts"],"names":[],"mappings":";;;;;;AACA,iDAAqC;AACrC,2BAA4D;AAC5D,0CAAsD;AACtD,gDAAuB;AACvB,6BAA6B;AAC7B,yCAAgD;AAChD,oDAAgD;AAChD,kFAKmC;AACnC,kEAA+C;AAC/C,4CAAmB;AACnB,+BAA6C;AAC7C,4EAAkD;AAClD,mDAAgE;AAChE,gEAA2D;AAK3D,+BAAgC;AAChC,iDAAoC;AAEpC,YAAY;AACZ,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;AAQpB,QAAA,gBAAgB,GAAG,EAAE,CAAA;AAChC,MAAqB,oBAAqB,SAAQ,UAAS;IAiBzD,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QAbR,oBAAe,GAAG,IAAI,0BAAe,EAAE,CAAA;QACvC,aAAQ,GAAG,IAAI,kBAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACnD,SAAI,GAAG,KAAK,CAAA;QAKZ,mBAAc,GAGhB,EAAE,CAAA;QAIN,IAAI,CAAC,gBAAgB,GAAG,IAAI,2BAAgB,CAAC,OAAO,CAAC,CAAA;QACrD,oBAAoB,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAA;QAC3D,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;QACxB,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAA;QAC1B,oBAAoB,CAAC,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK;YAC5D,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,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envelope, Meta } from '@cucumber/messages'\nimport { spawn } from 'child_process'\nimport { readFileSync, existsSync, writeFileSync } from 'fs'\nimport { mkdir, unlink, writeFile } from 'fs/promises'\nimport path from 'path'\nimport { tmpName } from 'tmp'\nimport Formatter, { IFormatterOptions } from '.'\nimport { doesHaveValue } from '../value_checker'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n JsonTestResult,\n RetrainStats,\n} from './helpers/report_generator'\nimport ReportUploader from './helpers/uploader'\nimport os from 'os'\nimport { getProjectByAccessKey } from './api'\nimport SummaryFormatter from './summary_formatter'\nimport { ActionEvents, SERVICES_URI } from './helpers/constants'\nimport { axiosClient } from '../configuration/axios_client'\nimport {\n FinishTestCaseResponse,\n RootCauseProps,\n} from './helpers/upload_serivce'\nimport { promisify } from 'util'\nimport { exec } from 'child_process'\n\n//User token\nconst TOKEN = process.env.TOKEN\ninterface MetaMessage extends Meta {\n runName: string\n}\n\ninterface EnvelopeWithMetaMessage extends Envelope {\n meta: MetaMessage\n}\nexport let globalReportLink = ''\nexport default class BVTAnalysisFormatter extends Formatter {\n static reportGenerator: ReportGenerator\n static reRunFailedStepsIndex:\n | { testCaseId: string; failedStepIndex: number }[]\n | null\n private reportGenerator = new ReportGenerator()\n private uploader = new ReportUploader(this.reportGenerator)\n private exit = false\n private START: number\n private runName: string\n private failedStepsIndex: { testCaseId: string; failedStepIndex: number }[]\n private summaryFormatter: SummaryFormatter\n private rootCauseArray: {\n rootCause: RootCauseProps\n report: JsonTestProgress\n }[] = []\n\n constructor(options: IFormatterOptions) {\n super(options)\n this.summaryFormatter = new SummaryFormatter(options)\n BVTAnalysisFormatter.reportGenerator = this.reportGenerator\n this.rootCauseArray = []\n this.failedStepsIndex = []\n BVTAnalysisFormatter.reRunFailedStepsIndex = process.env.RERUN\n ? JSON.parse(process.env.RERUN)\n : null\n\n if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {\n throw new Error('TOKEN must be set')\n }\n this.sendEvent(ActionEvents.cli_run_tests)\n options.eventBroadcaster.on(\n 'envelope',\n async (envelope: EnvelopeWithMetaMessage, data?: any) => {\n if (doesHaveValue(envelope.testCaseFinished) && data) {\n const { rootCause, report } = data as FinishTestCaseResponse\n\n if (!rootCause.status) {\n console.error(\n `Root cause: ${rootCause.failClass}\\n, ${rootCause.analysis}\\nfailing step: ${rootCause.failedStep}`\n )\n this.rootCauseArray.push({ rootCause, report })\n this.failedStepsIndex.push({\n testCaseId: report.id,\n failedStepIndex: rootCause.failedStep,\n })\n }\n return\n }\n await this.reportGenerator.handleMessage(envelope)\n\n if (\n doesHaveValue(envelope.meta) &&\n doesHaveValue(envelope.meta.runName)\n ) {\n this.runName = envelope.meta.runName\n }\n if (doesHaveValue(envelope.testRunFinished)) {\n this.START = Date.now()\n if (process.env.BVT_FORMATTER === 'ANALYSIS') {\n await this.analyzeReport()\n } else {\n // await this.uploadReport(report)\n }\n this.exit = true\n }\n }\n )\n }\n\n private sendEvent(event: ActionEvents) {\n axiosClient\n .post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event,\n },\n {\n headers: {\n Authorization: `Bearer ${TOKEN}`,\n 'x-source': 'cucumber_js',\n },\n }\n )\n .catch((err) => {\n // Error with events, ignoring\n })\n }\n\n private async uploadReport(report: JsonReport) {\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful && report.result.status !== 'FAILED') {\n process.exit(0)\n }\n process.exit(1)\n }\n\n async finished(): Promise<any> {\n await new Promise((resolve) => {\n const checkInterval = setInterval(() => {\n let anyRem\n if (process.env.UPLOADING_TEST_CASE) {\n anyRem = JSON.parse(process.env.UPLOADING_TEST_CASE) as string[]\n } else {\n anyRem = undefined\n }\n\n if (this.exit && (!anyRem || anyRem.length === 0)) {\n // clearInterval(checkInterval)\n // resolve(null)\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n } else {\n process.exit(0)\n }\n }\n }, 100) // check every 100ms\n })\n }\n private async analyzeReport() {\n if (\n this.rootCauseArray.length === 0 ||\n process.env.NO_RETRAIN === 'false'\n ) {\n if (this.rootCauseArray.length === 0) {\n this.log('No test failed. No need to retrain\\n')\n }\n if (process.env.NO_RETRAIN === 'false') {\n this.log(\n 'Retraining is skipped since the failed step contains an API request\\n'\n )\n }\n // const uploadSuccessful = await this.uploadFinalReport(report)\n // process.exit(0)\n this.exit = true\n return\n }\n\n //checking if the type of report.result is JsonResultFailed or not\n\n this.log('Some tests failed, starting the retraining...\\n')\n await this.processTestCases()\n if (this.reportGenerator.getReport().result.status === 'FAILED') {\n process.exit(1)\n }\n process.exit(0)\n }\n private async processTestCases() {\n for (const { rootCause, report } of this.rootCauseArray) {\n await this.processTestCase(rootCause, report)\n }\n }\n private async processTestCase(\n rootCause: RootCauseProps,\n report: JsonTestProgress\n ) {\n const failedTestSteps = rootCause.failedStep\n\n if (\n BVTAnalysisFormatter.reRunFailedStepsIndex &&\n BVTAnalysisFormatter.reRunFailedStepsIndex.length > 0\n ) {\n const previousRun = BVTAnalysisFormatter.reRunFailedStepsIndex[0]\n if (previousRun.failedStepIndex === failedTestSteps) {\n console.log('Same step has failed again, skipping retraining')\n BVTAnalysisFormatter.reRunFailedStepsIndex.shift()\n return\n }\n BVTAnalysisFormatter.reRunFailedStepsIndex.shift()\n }\n\n if (process.env.RERUN) {\n await this.uploader.modifyTestCase({\n ...report,\n })\n return\n }\n\n const retrainStats = await this.retrain(failedTestSteps, report)\n\n if (retrainStats) {\n await this.uploader.modifyTestCase({\n ...report,\n retrainStats,\n })\n } else {\n this.log(`No stats found retraining...`)\n }\n await this.rerun(report)\n }\n\n private async uploadFinalReport(finalReport: JsonReport) {\n let success = true\n try {\n const { projectId, runId } = await this.uploader.uploadRun(\n finalReport,\n this.runName\n )\n logReportLink(runId, projectId, finalReport.result)\n } catch (err) {\n this.log('Error uploading report\\n')\n if ('stack' in err) {\n this.log(err.stack)\n }\n success = false\n } finally {\n try {\n writeFileSync(\n path.join(this.reportGenerator.reportFolder, 'report.json'),\n JSON.stringify(finalReport, null, 2),\n 'utf-8'\n )\n } catch (e) {\n console.error('failed to write report.json to local disk')\n }\n }\n\n //this.log(JSON.stringify(finalReport, null, 2))\n return success\n }\n private async retrain(\n failedTestCases: number,\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n const data = await getProjectByAccessKey(TOKEN)\n const currentTimestampInSeconds = Math.floor(Date.now() / 1000)\n if (data.project.expriration_date < currentTimestampInSeconds) {\n console.log(\n 'Warning: Your project has expired, retraining is restricted. Please contact sales.'\n )\n process.exit(1)\n }\n return await this.call_cucumber_client(failedTestCases, testCase)\n }\n\n private async rerun(report: JsonTestProgress) {\n await new Promise<void>((resolve) => {\n // Default to system Node.js\n const node_path = process.execPath\n\n // Use bundled Node if running from recorder app on macOS or Windows\n const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true'\n\n const args = [\n path.join(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber-js',\n 'bin',\n 'cucumber.js'\n ),\n '--name',\n `^${report.scenarioName}$`,\n '--exit',\n '--format',\n 'bvt',\n '--run-name',\n `${report.scenarioName}@debug`,\n path.join(process.cwd(), report.uri),\n ]\n\n const envVars: NodeJS.ProcessEnv = {\n ...process.env,\n RERUN: JSON.stringify(this.failedStepsIndex),\n }\n\n // Inject Electron node env only if using electron's bundled node\n if (isFromRecorderApp) {\n envVars.ELECTRON_RUN_AS_NODE = '1'\n }\n\n const cucumberJSChildProcess = spawn(node_path!, args, {\n env: envVars,\n })\n\n cucumberJSChildProcess.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberJSChildProcess.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberJSChildProcess.on('close', () => {\n resolve()\n })\n })\n }\n\n private async call_cucumber_client(\n stepsToRetrain: number,\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n return new Promise((resolve, reject) => {\n const cucumber_client_path = path.resolve(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber_client',\n 'bin',\n 'client',\n 'cucumber.js'\n )\n\n const args: string[] = [\n process.cwd(),\n path.join(process.cwd(), testCase.uri),\n `${testCase.scenarioName}`,\n 'undefined',\n `${stepsToRetrain},`,\n ]\n\n if (process.env.BLINQ_ENV) {\n args.push(`--env=${process.env.BLINQ_ENV}`)\n }\n\n if (!existsSync(path.join(this.getAppDataDir(), 'blinq.io', '.temp'))) {\n mkdir(path.join(this.getAppDataDir(), 'blinq.io', '.temp'), {\n recursive: true,\n })\n }\n\n tmpName(async (err, name) => {\n const tempFile = path.join(\n this.getAppDataDir(),\n 'blinq.io',\n '.temp',\n path.basename(name)\n )\n console.log('File path: ', tempFile)\n\n if (!existsSync(path.dirname(tempFile))) {\n await mkdir(path.dirname(tempFile), { recursive: true })\n }\n await writeFile(tempFile, '', 'utf-8')\n\n args.push(`--temp-file=${tempFile}`)\n\n // Determine node path\n const isFromRecorderApp = process.env.FROM_RECORDER_APP === 'true'\n const node_path = process.execPath\n\n const envVars: NodeJS.ProcessEnv = {\n ...process.env,\n TEMP_FILE_PATH: tempFile,\n TRACE: undefined,\n }\n\n if (isFromRecorderApp) {\n envVars.ELECTRON_RUN_AS_NODE = '1'\n }\n\n const cucumberClient = spawn(\n node_path,\n [cucumber_client_path, ...args],\n {\n env: envVars,\n }\n )\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', async (code) => {\n try {\n if (code === 0) {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n } else {\n this.log('Error retraining\\n')\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n await unlink(tempFile)\n resolve(retrainStats)\n }\n } catch (e) {\n const message = e.message\n const stack = e.stack\n this.log(\n `Error occured while reading scenario report:${message}\\n${stack}`\n )\n resolve(null)\n }\n })\n })\n })\n }\n\n private getAppDataDir() {\n if (process.env.BLINQ_APPDATA_DIR) {\n return process.env.BLINQ_APPDATA_DIR\n }\n\n let appDataDir: string\n\n switch (process.platform) {\n case 'win32':\n appDataDir = process.env.APPDATA!\n break\n case 'darwin':\n appDataDir = path.join(os.homedir(), 'Library', 'Application Support')\n break\n default:\n appDataDir = path.join(os.homedir(), '.config')\n break\n }\n return appDataDir\n }\n}\n\nexport function logReportLink(\n runId: string,\n projectId: string,\n status: JsonTestResult\n) {\n let reportLinkBaseUrl = 'https://app.blinq.io'\n if (process.env.NODE_ENV_BLINQ === 'local') {\n reportLinkBaseUrl = 'http://localhost:3000'\n } else if (process.env.NODE_ENV_BLINQ === 'dev') {\n reportLinkBaseUrl = 'https://dev.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'stage') {\n reportLinkBaseUrl = 'https://stage.app.blinq.io'\n } else if (process.env.NODE_ENV_BLINQ === 'prod') {\n reportLinkBaseUrl = 'https://app.blinq.io'\n } else if (!process.env.NODE_ENV_BLINQ) {\n reportLinkBaseUrl = 'https://app.blinq.io'\n } else {\n reportLinkBaseUrl = process.env.NODE_ENV_BLINQ.replace('api', 'app')\n }\n const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`\n globalReportLink = reportLink\n try {\n publishReportLinkToGuacServer(reportLink, status.status === 'PASSED')\n } catch (err) {\n // Error with events, ignoring\n }\n return reportLink\n}\n\nfunction publishReportLinkToGuacServer(reportLink: string, result: boolean) {\n if (existsSync('/tmp/report_publish.sh')) {\n const execAsync = promisify(exec)\n execAsync('sh /tmp/report_publish.sh ' + reportLink + ' ' + result)\n }\n}\n\nexport async function postUploadReportEvent(\n projectId: string,\n accessToken: string\n) {\n try {\n await axiosClient.post(\n `${SERVICES_URI.STORAGE}/event`,\n { event: ActionEvents.upload_report },\n {\n headers: {\n Authorization: 'Bearer ' + accessToken,\n 'x-source': 'cucumber_js',\n 'x-bvt-project-id': projectId,\n },\n }\n )\n } catch {}\n}\n\nexport async function createNewTestCase(\n payload: any,\n runsApiBaseURL: string,\n accessToken: string\n): Promise<any> {\n const jsonSizeKB = Buffer.byteLength(JSON.stringify(payload)) / 1024\n\n if (jsonSizeKB > 10240) {\n // 10 MB\n console.warn(\n `⚠️ Payload exceeds recommended size of 10MB: ${jsonSizeKB} KB`\n )\n }\n\n const MAX_RETRIES = 3\n const RETRY_DELAY_MS = 1000\n\n for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {\n const start = Date.now()\n try {\n const { data } = await axiosClient.post(\n `${runsApiBaseURL}/cucumber-runs/createNewTestCase`,\n payload,\n {\n headers: {\n Authorization: 'Bearer ' + accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n return data\n } catch (e: any) {\n const isLastAttempt = attempt === MAX_RETRIES\n const errInfo = {\n attempt,\n message: e?.message,\n status: e?.response?.status,\n responseSnippet: e?.response?.data?.toString()?.slice(0, 300),\n durationMs: Date.now() - start,\n }\n console.error(\n '🟥 Failed to POST /createNewTestCase:',\n JSON.stringify(errInfo, null, 2)\n )\n\n if (isLastAttempt) throw e\n\n await new Promise((r) => setTimeout(r, RETRY_DELAY_MS * attempt))\n }\n }\n}\n"]}
@@ -4,10 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateExamplesFromFunctionGherkin = exports.generateExamplesFromFunction = exports.generateTestData = void 0;
7
- const faker_1 = require("@faker-js/faker");
7
+ // import { faker } from '@faker-js/faker' // it is taking more time to load the module
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const json5_1 = __importDefault(require("json5"));
11
+ const try_require_1 = __importDefault(require("../try_require"));
11
12
  const generateTestData = (featureFileContent, vars, fakeData, projectDir) => {
12
13
  const regexp = /\{\{([^}]*\([^)]*\))\}\}/g;
13
14
  const variableRegex = /^([a-zA-Z0-9_]*)=(.*)/g;
@@ -75,11 +76,19 @@ const generateTestData = (featureFileContent, vars, fakeData, projectDir) => {
75
76
  if (namespaces.includes(match[1].split('.')[0]))
76
77
  continue;
77
78
  try {
78
- const fake = duplicateFakeData &&
79
- duplicateFakeData.length > 0 &&
80
- duplicateFakeData[0].var === match[0]
81
- ? duplicateFakeData.shift().fake
82
- : getFakeString(match[0].substring(2, match[0].length - 2));
79
+ let fake;
80
+ if (!duplicateFakeData || duplicateFakeData.length === 0) {
81
+ fake = getFakeString(match[0].substring(2, match[0].length - 2));
82
+ }
83
+ else {
84
+ const foundDuplicate = duplicateFakeData.find((item) => item.var === match[0]);
85
+ if (foundDuplicate) {
86
+ fake = foundDuplicate.fake;
87
+ }
88
+ else {
89
+ fake = getFakeString(match[0].substring(2, match[0].length - 2));
90
+ }
91
+ }
83
92
  otherFakeData.push({
84
93
  var: match[0],
85
94
  fake,
@@ -89,7 +98,6 @@ const generateTestData = (featureFileContent, vars, fakeData, projectDir) => {
89
98
  }
90
99
  catch (err) {
91
100
  // eslint-disable-next-line no-console
92
- console.log('unknown faker variable:' + match[0]);
93
101
  }
94
102
  }
95
103
  return {
@@ -101,13 +109,19 @@ const generateTestData = (featureFileContent, vars, fakeData, projectDir) => {
101
109
  };
102
110
  };
103
111
  exports.generateTestData = generateTestData;
112
+ let globalFaker = null;
104
113
  const getFakeString = (content) => {
105
114
  // content example: helpers.fromRegExp('#{2,9}')
106
115
  const faking = content.split('(')[0].split('.');
107
116
  // faking example: ['helpers', 'fromRegExp']
108
117
  const argument = content.substring(content.indexOf('(') + 1, content.lastIndexOf(')'));
109
118
  // argument example: '#{2,9}'
110
- let fakeFunc = faker_1.faker;
119
+ let faker = globalFaker;
120
+ if (!faker) {
121
+ faker = (0, try_require_1.default)('@faker-js/faker/locale/en_US').faker;
122
+ globalFaker = faker;
123
+ }
124
+ let fakeFunc = faker;
111
125
  faking.forEach((f) => {
112
126
  fakeFunc = fakeFunc[f];
113
127
  });