@dev-blinq/cucumber-js 1.0.106 → 1.0.107

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.
@@ -34,16 +34,16 @@ const upload_serivce_1 = require("./upload_serivce");
34
34
  const fs_extra_1 = require("fs-extra");
35
35
  // type JsonException = messages.Exception
36
36
  const object_path_1 = __importDefault(require("object-path"));
37
- const URL = process.env.NODE_ENV_BLINQ === "dev"
38
- ? "https://dev.api.blinq.io/api/runs"
39
- : process.env.NODE_ENV_BLINQ === "local"
40
- ? "http://localhost:5001/api/runs"
41
- : process.env.NODE_ENV_BLINQ === "stage"
42
- ? "https://stage.api.blinq.io/api/runs"
43
- : process.env.NODE_ENV_BLINQ === "prod"
44
- ? "https://api.blinq.io/api/runs"
37
+ const URL = process.env.NODE_ENV_BLINQ === 'dev'
38
+ ? 'https://dev.api.blinq.io/api/runs'
39
+ : process.env.NODE_ENV_BLINQ === 'local'
40
+ ? 'http://localhost:5001/api/runs'
41
+ : process.env.NODE_ENV_BLINQ === 'stage'
42
+ ? 'https://stage.api.blinq.io/api/runs'
43
+ : process.env.NODE_ENV_BLINQ === 'prod'
44
+ ? 'https://api.blinq.io/api/runs'
45
45
  : !process.env.NODE_ENV_BLINQ
46
- ? "https://api.blinq.io/api/runs"
46
+ ? 'https://api.blinq.io/api/runs'
47
47
  : `${process.env.NODE_ENV_BLINQ}/api/runs`;
48
48
  const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
49
49
  const BATCH_SIZE = 10;
@@ -53,12 +53,12 @@ class ReportGenerator {
53
53
  constructor() {
54
54
  this.report = {
55
55
  result: {
56
- status: "UNKNOWN",
56
+ status: 'UNKNOWN',
57
57
  },
58
58
  testCases: [],
59
59
  env: {
60
- name: "",
61
- baseUrl: "",
60
+ name: '',
61
+ baseUrl: '',
62
62
  },
63
63
  };
64
64
  this.gherkinDocumentMap = new Map();
@@ -73,45 +73,46 @@ class ReportGenerator {
73
73
  this.networkLog = [];
74
74
  this.stepLogs = [];
75
75
  this.stepNetworkLogs = [];
76
- this.runName = "";
77
- this.ariaSnapshot = "";
78
- this.initialAriaSnapshot = "";
76
+ this.runName = '';
77
+ this.ariaSnapshot = '';
78
+ this.initialAriaSnapshot = '';
79
79
  this.testCaseLog = [];
80
80
  this.loggingOverridden = false; // Flag to track if logging is overridden
81
81
  this.reportFolder = null;
82
82
  this.uploadService = new upload_serivce_1.RunUploadService(REPORT_SERVICE_URL, REPORT_SERVICE_TOKEN);
83
83
  }
84
84
  async handleMessage(envelope, reRunId) {
85
- if (envelope.meta && "runName" in envelope.meta) {
85
+ if (envelope.meta && 'runName' in envelope.meta) {
86
86
  this.runName = envelope.meta.runName;
87
87
  }
88
88
  const type = Object.keys(envelope)[0];
89
89
  switch (type) {
90
90
  // case "meta": { break}
91
91
  // case "source": { break}
92
- case "parseError": {
92
+ case 'parseError': {
93
93
  const parseError = envelope[type];
94
94
  this.handleParseError(parseError);
95
95
  break;
96
96
  }
97
- case "gherkinDocument": {
97
+ case 'gherkinDocument': {
98
98
  const doc = envelope[type];
99
99
  this.onGherkinDocument(doc);
100
100
  break;
101
101
  }
102
- case "pickle": {
102
+ case 'pickle': {
103
103
  const pickle = envelope[type];
104
104
  this.onPickle(pickle);
105
105
  break;
106
106
  }
107
107
  // case "stepDefinition": { break}
108
108
  // case "hook": { break} // Before Hook
109
- case "testRunStarted": {
109
+ case 'testRunStarted': {
110
110
  const testRunStarted = envelope[type];
111
111
  this.onTestRunStarted(testRunStarted);
112
+ await this.uploadService.createStatus('running');
112
113
  break;
113
114
  }
114
- case "testCase": {
115
+ case 'testCase': {
115
116
  const testCase = envelope[type];
116
117
  // Initialize the log storage
117
118
  this.testCaseLog = [];
@@ -135,36 +136,36 @@ class ReportGenerator {
135
136
  this.onTestCase(testCase);
136
137
  break;
137
138
  }
138
- case "testCaseStarted": {
139
+ case 'testCaseStarted': {
139
140
  const testCaseStarted = envelope[type];
140
141
  this.onTestCaseStarted(testCaseStarted);
141
142
  break;
142
143
  }
143
- case "testStepStarted": {
144
+ case 'testStepStarted': {
144
145
  const testStepStarted = envelope[type];
145
146
  this.onTestStepStarted(testStepStarted);
146
147
  break;
147
148
  }
148
- case "attachment": {
149
+ case 'attachment': {
149
150
  const attachment = envelope[type];
150
151
  this.onAttachment(attachment);
151
152
  break;
152
153
  }
153
- case "testStepFinished": {
154
+ case 'testStepFinished': {
154
155
  const testStepFinished = envelope[type];
155
156
  this.onTestStepFinished(testStepFinished);
156
157
  break;
157
158
  }
158
- case "testCaseFinished": {
159
+ case 'testCaseFinished': {
159
160
  const testCaseFinished = envelope[type];
160
161
  // Call the onTestCaseFinished method
161
162
  const result = await this.onTestCaseFinished(testCaseFinished, reRunId);
162
163
  return result;
163
164
  }
164
165
  // case "hook": { break} // After Hook
165
- case "testRunFinished": {
166
+ case 'testRunFinished': {
166
167
  const testRunFinished = envelope[type];
167
- this.onTestRunFinished(testRunFinished);
168
+ await this.onTestRunFinished(testRunFinished);
168
169
  break;
169
170
  }
170
171
  // case "parameterType" : { break}
@@ -178,7 +179,7 @@ class ReportGenerator {
178
179
  const { message } = parseError;
179
180
  const timestamp = new Date().getTime();
180
181
  this.report.result = {
181
- status: "FAILED",
182
+ status: 'FAILED',
182
183
  startTime: timestamp,
183
184
  endTime: timestamp,
184
185
  message: message,
@@ -221,7 +222,7 @@ class ReportGenerator {
221
222
  }
222
223
  onTestRunStarted(testRunStarted) {
223
224
  this.report.result = {
224
- status: "STARTED",
225
+ status: 'STARTED',
225
226
  startTime: this.getTimeStamp(testRunStarted.timestamp),
226
227
  };
227
228
  }
@@ -254,7 +255,8 @@ class ReportGenerator {
254
255
  for (const tableRow of examples.tableBody) {
255
256
  if (tableRow.id === exampleId) {
256
257
  for (let i = 0; i < examples.tableHeader.cells.length; i++) {
257
- parameters[examples.tableHeader.cells[i].value] = tableRow.cells[i].value;
258
+ parameters[examples.tableHeader.cells[i].value] =
259
+ tableRow.cells[i].value;
258
260
  }
259
261
  }
260
262
  }
@@ -292,7 +294,7 @@ class ReportGenerator {
292
294
  text: step.text,
293
295
  commands: [],
294
296
  result: {
295
- status: "UNKNOWN",
297
+ status: 'UNKNOWN',
296
298
  },
297
299
  networkData: [],
298
300
  webLog: [],
@@ -309,7 +311,7 @@ class ReportGenerator {
309
311
  parameters,
310
312
  steps,
311
313
  result: {
312
- status: "STARTED",
314
+ status: 'STARTED',
313
315
  startTime: this.getTimeStamp(timestamp),
314
316
  },
315
317
  webLog: [],
@@ -330,25 +332,25 @@ class ReportGenerator {
330
332
  return;
331
333
  const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
332
334
  stepProgess.result = {
333
- status: "STARTED",
335
+ status: 'STARTED',
334
336
  startTime: this.getTimeStamp(timestamp),
335
337
  };
336
338
  }
337
339
  onAttachment(attachment) {
338
340
  const { testStepId, body, mediaType } = attachment;
339
- if (mediaType === "text/plain") {
340
- this.reportFolder = body.replaceAll("\\", "/");
341
+ if (mediaType === 'text/plain') {
342
+ this.reportFolder = body.replaceAll('\\', '/');
341
343
  return;
342
344
  }
343
- if (mediaType === "application/json+snapshot-before") {
345
+ if (mediaType === 'application/json+snapshot-before') {
344
346
  this.initialAriaSnapshot = body;
345
347
  return;
346
348
  }
347
- if (mediaType === "application/json+snapshot-after") {
349
+ if (mediaType === 'application/json+snapshot-after') {
348
350
  this.ariaSnapshot = body;
349
351
  return;
350
352
  }
351
- if (mediaType === "application/json+env") {
353
+ if (mediaType === 'application/json+env') {
352
354
  const data = JSON.parse(body);
353
355
  this.report.env = data;
354
356
  this.report.testCases.map((testCase) => {
@@ -356,14 +358,14 @@ class ReportGenerator {
356
358
  return testCase;
357
359
  });
358
360
  }
359
- if (mediaType === "application/json+log") {
361
+ if (mediaType === 'application/json+log') {
360
362
  const log = JSON.parse(body);
361
363
  if (this.logs.length < 1000) {
362
364
  this.logs.push(log);
363
365
  this.stepLogs.push(log);
364
366
  }
365
367
  }
366
- if (mediaType === "application/json+network") {
368
+ if (mediaType === 'application/json+network') {
367
369
  const networkLog = JSON.parse(body);
368
370
  if (this.networkLog.length < 1000)
369
371
  this.networkLog.push(networkLog);
@@ -373,29 +375,29 @@ class ReportGenerator {
373
375
  if (testStep.pickleStepId === undefined)
374
376
  return;
375
377
  const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
376
- if (mediaType === "application/json") {
378
+ if (mediaType === 'application/json') {
377
379
  const command = JSON.parse(body);
378
380
  stepProgess.commands.push(command);
379
381
  }
380
- else if (mediaType === "application/json+trace") {
382
+ else if (mediaType === 'application/json+trace') {
381
383
  const data = JSON.parse(body);
382
384
  stepProgess.traceFilePath = data.traceFilePath;
383
385
  }
384
- if (mediaType === "application/json+bruno") {
386
+ if (mediaType === 'application/json+bruno') {
385
387
  try {
386
388
  const data = JSON.parse(body);
387
389
  stepProgess.brunoData = data;
388
390
  }
389
391
  catch (error) {
390
- console.error("Error parsing bruno data:", error);
392
+ console.error('Error parsing bruno data:', error);
391
393
  }
392
394
  }
393
395
  }
394
396
  getFailedTestStepResult({ commands, startTime, endTime, result, }) {
395
397
  for (const command of commands) {
396
- if (command.result.status === "FAILED") {
398
+ if (command.result.status === 'FAILED') {
397
399
  return {
398
- status: "FAILED",
400
+ status: 'FAILED',
399
401
  message: command.result.message,
400
402
  startTime,
401
403
  endTime,
@@ -403,7 +405,7 @@ class ReportGenerator {
403
405
  }
404
406
  }
405
407
  return {
406
- status: "FAILED",
408
+ status: 'FAILED',
407
409
  startTime,
408
410
  endTime,
409
411
  message: result.message,
@@ -413,26 +415,26 @@ class ReportGenerator {
413
415
  const { testStepId, testStepResult, timestamp } = testStepFinished;
414
416
  const testStep = this.testStepMap.get(testStepId);
415
417
  if (testStep.pickleStepId === undefined) {
416
- if (testStepResult.status === "FAILED") {
418
+ if (testStepResult.status === 'FAILED') {
417
419
  console.error(`Before/After hook failed with message: ${testStepResult.message}`);
418
420
  }
419
421
  return;
420
422
  }
421
- if (testStepResult.status === "UNDEFINED") {
423
+ if (testStepResult.status === 'UNDEFINED') {
422
424
  const step = this.stepReportMap.get(testStep.pickleStepId);
423
- const stepName = step ? step.keyword + " " + step.text : "Undefined step";
425
+ const stepName = step ? step.keyword + ' ' + step.text : 'Undefined step';
424
426
  const undefinedCommand = {
425
427
  testStepId: testStepId,
426
428
  body: JSON.stringify({
427
- type: "error",
428
- text: "Undefined step: " + stepName,
429
+ type: 'error',
430
+ text: 'Undefined step: ' + stepName,
429
431
  result: {
430
- status: "FAILED",
432
+ status: 'FAILED',
431
433
  startTime: this.getTimeStamp(timestamp),
432
434
  endTime: this.getTimeStamp(timestamp),
433
435
  },
434
436
  }),
435
- mediaType: "application/json",
437
+ mediaType: 'application/json',
436
438
  contentEncoding: messages.AttachmentContentEncoding.IDENTITY,
437
439
  };
438
440
  this.onAttachment(undefinedCommand);
@@ -445,14 +447,14 @@ class ReportGenerator {
445
447
  if (reportFolder === null) {
446
448
  throw new Error('"reportFolder" is "null". Failed to run BVT hooks. Please retry after running "Generate All" or "Record Scenario" ');
447
449
  }
448
- if (fs_1.default.existsSync(path_1.default.join(reportFolder, "data.json"))) {
449
- data = JSON.parse(fs_1.default.readFileSync(path_1.default.join(reportFolder, "data.json"), "utf8"));
450
+ if (fs_1.default.existsSync(path_1.default.join(reportFolder, 'data.json'))) {
451
+ data = JSON.parse(fs_1.default.readFileSync(path_1.default.join(reportFolder, 'data.json'), 'utf8'));
450
452
  }
451
453
  }
452
454
  catch (error) {
453
- console.log("Error reading data.json");
455
+ console.log('Error reading data.json');
454
456
  }
455
- if (testStepResult.status === "FAILED") {
457
+ if (testStepResult.status === 'FAILED') {
456
458
  stepProgess.result = this.getFailedTestStepResult({
457
459
  commands: stepProgess.commands,
458
460
  startTime: prevStepResult.startTime,
@@ -470,7 +472,7 @@ class ReportGenerator {
470
472
  stepProgess.webLog = this.stepLogs;
471
473
  stepProgess.networkData = this.stepNetworkLogs;
472
474
  stepProgess.ariaSnapshot = this.ariaSnapshot;
473
- this.ariaSnapshot = "";
475
+ this.ariaSnapshot = '';
474
476
  this.stepNetworkLogs = [];
475
477
  this.stepLogs = [];
476
478
  if (Object.keys(data).length > 0) {
@@ -479,18 +481,19 @@ class ReportGenerator {
479
481
  const parameters = this.testCaseReportMap.get(id).parameters;
480
482
  const _parameters = {};
481
483
  Object.keys(parameters).map((key) => {
482
- if (parameters[key].startsWith("{{") && parameters[key].endsWith("}}")) {
483
- const path = parameters[key].slice(2, -2).split(".");
484
+ if (parameters[key].startsWith('{{') &&
485
+ parameters[key].endsWith('}}')) {
486
+ const path = parameters[key].slice(2, -2).split('.');
484
487
  let value = String(object_path_1.default.get(data, path));
485
488
  if (value) {
486
- if (value.startsWith("secret:")) {
487
- value = "secret:****";
489
+ if (value.startsWith('secret:')) {
490
+ value = 'secret:****';
488
491
  }
489
- else if (value.startsWith("totp:")) {
490
- value = "totp:****";
492
+ else if (value.startsWith('totp:')) {
493
+ value = 'totp:****';
491
494
  }
492
- else if (value.startsWith("mask:")) {
493
- value = "mask:****";
495
+ else if (value.startsWith('mask:')) {
496
+ value = 'mask:****';
494
497
  }
495
498
  _parameters[key] = value;
496
499
  }
@@ -523,7 +526,7 @@ class ReportGenerator {
523
526
  if (process.env.PROJECT_PATH) {
524
527
  projectPath = process.env.PROJECT_PATH;
525
528
  }
526
- const logFolder = path_1.default.join(projectPath, "logs", "web");
529
+ const logFolder = path_1.default.join(projectPath, 'logs', 'web');
527
530
  if (!fs_1.default.existsSync(logFolder)) {
528
531
  return [];
529
532
  }
@@ -535,7 +538,7 @@ class ReportGenerator {
535
538
  return [];
536
539
  }
537
540
  try {
538
- const logFileContent = fs_1.default.readFileSync(path_1.default.join(logFolder, `${nextId - 1}.json`), "utf8");
541
+ const logFileContent = fs_1.default.readFileSync(path_1.default.join(logFolder, `${nextId - 1}.json`), 'utf8');
539
542
  return JSON.parse(logFileContent);
540
543
  }
541
544
  catch (error) {
@@ -545,23 +548,23 @@ class ReportGenerator {
545
548
  getTestCaseResult(steps) {
546
549
  for (const step of steps) {
547
550
  switch (step.result.status) {
548
- case "FAILED":
551
+ case 'FAILED':
549
552
  return {
550
553
  status: step.result.status,
551
554
  message: step.result.message,
552
555
  // exception: step.result.exception,
553
556
  };
554
- case "AMBIGUOUS":
555
- case "UNDEFINED":
556
- case "PENDING":
557
+ case 'AMBIGUOUS':
558
+ case 'UNDEFINED':
559
+ case 'PENDING':
557
560
  return {
558
- status: "FAILED",
561
+ status: 'FAILED',
559
562
  message: `step "${step.text}" is ${step.result.status}`,
560
563
  };
561
564
  }
562
565
  }
563
566
  return {
564
- status: "PASSED",
567
+ status: 'PASSED',
565
568
  };
566
569
  }
567
570
  async onTestCaseFinished(testCaseFinished, reRunId) {
@@ -579,7 +582,7 @@ class ReportGenerator {
579
582
  testProgress.webLog = this.logs;
580
583
  testProgress.networkLog = this.networkLog;
581
584
  testProgress.initialAriaSnapshot = this.initialAriaSnapshot;
582
- this.initialAriaSnapshot = "";
585
+ this.initialAriaSnapshot = '';
583
586
  this.networkLog = [];
584
587
  this.logs = [];
585
588
  if (this.testCaseLog && this.testCaseLog.length > 0) {
@@ -609,10 +612,10 @@ class ReportGenerator {
609
612
  }
610
613
  }
611
614
  async uploadTestCase(testCase, rerunId) {
612
- let runId = "";
613
- let projectId = "";
615
+ let runId = '';
616
+ let projectId = '';
614
617
  if (!process.env.UPLOADING_TEST_CASE) {
615
- process.env.UPLOADING_TEST_CASE = "[]";
618
+ process.env.UPLOADING_TEST_CASE = '[]';
616
619
  }
617
620
  const anyRemArr = JSON.parse(process.env.UPLOADING_TEST_CASE);
618
621
  const randomID = Math.random().toString(36).substring(7);
@@ -620,7 +623,9 @@ class ReportGenerator {
620
623
  let data;
621
624
  process.env.UPLOADING_TEST_CASE = JSON.stringify(anyRemArr);
622
625
  try {
623
- if (process.env.RUN_ID && process.env.PROJECT_ID && !process.env.IGNORE_ENV_VARIABLES) {
626
+ if (process.env.RUN_ID &&
627
+ process.env.PROJECT_ID &&
628
+ !process.env.IGNORE_ENV_VARIABLES) {
624
629
  runId = process.env.RUN_ID;
625
630
  projectId = process.env.PROJECT_ID;
626
631
  }
@@ -637,7 +642,7 @@ class ReportGenerator {
637
642
  this.writeTestCaseReportToDisk(testCase);
638
643
  }
639
644
  catch (e) {
640
- console.error("Error uploading test case:", e);
645
+ console.error('Error uploading test case:', e);
641
646
  }
642
647
  finally {
643
648
  const arrRem = JSON.parse(process.env.UPLOADING_TEST_CASE);
@@ -650,7 +655,7 @@ class ReportGenerator {
650
655
  var _a;
651
656
  const reportFolder = (_a = this.reportFolder) !== null && _a !== void 0 ? _a : process.env.TESTCASE_REPORT_FOLDER_PATH;
652
657
  if (!reportFolder) {
653
- console.error("Report folder is not defined");
658
+ console.error('Report folder is not defined');
654
659
  return;
655
660
  }
656
661
  try {
@@ -666,19 +671,20 @@ class ReportGenerator {
666
671
  fs_1.default.writeFileSync(path_1.default.join(reportFolder, `${i}`, `network.json`), JSON.stringify(networkLog, null, 2));
667
672
  }
668
673
  catch (error) {
669
- console.error("Error writing test case report to disk:", error);
674
+ console.error('Error writing test case report to disk:', error);
670
675
  }
671
676
  }
672
- onTestRunFinished(testRunFinished) {
677
+ async onTestRunFinished(testRunFinished) {
673
678
  const { timestamp, success, message } = testRunFinished;
674
679
  const prevResult = this.report.result;
675
680
  this.report.result = {
676
- status: success ? "PASSED" : "FAILED",
681
+ status: success ? 'PASSED' : 'FAILED',
677
682
  startTime: prevResult.startTime,
678
683
  endTime: this.getTimeStamp(timestamp),
679
684
  message,
680
685
  // exception,
681
686
  };
687
+ await this.uploadService.createStatus(success ? 'passed' : 'failed');
682
688
  }
683
689
  }
684
690
  exports.default = ReportGenerator;