@dev-blinq/cucumber-js 1.0.0 → 1.0.1-amdocs

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 (58) hide show
  1. package/README.md +40 -96
  2. package/bin/cucumber.ts +2 -0
  3. package/bin/download-install.js +175 -0
  4. package/lib/api/convert_configuration.js +1 -0
  5. package/lib/api/convert_configuration.js.map +1 -1
  6. package/lib/api/gherkin.js +81 -0
  7. package/lib/api/gherkin.js.map +1 -1
  8. package/lib/api/run_cucumber.d.ts +1 -1
  9. package/lib/api/run_cucumber.js +10 -10
  10. package/lib/api/run_cucumber.js.map +1 -1
  11. package/lib/api/types.d.ts +5 -3
  12. package/lib/api/types.js.map +1 -1
  13. package/lib/cli/helpers.d.ts +8 -6
  14. package/lib/cli/helpers.js +27 -6
  15. package/lib/cli/helpers.js.map +1 -1
  16. package/lib/cli/index.js +7 -2
  17. package/lib/cli/index.js.map +1 -1
  18. package/lib/configuration/argv_parser.js +4 -2
  19. package/lib/configuration/argv_parser.js.map +1 -1
  20. package/lib/configuration/axios_client.d.ts +1 -0
  21. package/lib/configuration/axios_client.js +40 -0
  22. package/lib/configuration/axios_client.js.map +1 -0
  23. package/lib/configuration/default_configuration.js +2 -0
  24. package/lib/configuration/default_configuration.js.map +1 -1
  25. package/lib/configuration/types.d.ts +2 -0
  26. package/lib/configuration/types.js.map +1 -1
  27. package/lib/formatter/api.d.ts +2 -0
  28. package/lib/formatter/api.js +57 -0
  29. package/lib/formatter/api.js.map +1 -0
  30. package/lib/formatter/bvt_analysis_formatter.d.ts +30 -0
  31. package/lib/formatter/bvt_analysis_formatter.js +342 -0
  32. package/lib/formatter/bvt_analysis_formatter.js.map +1 -0
  33. package/lib/formatter/feature_data_format.d.ts +23 -0
  34. package/lib/formatter/feature_data_format.js +182 -0
  35. package/lib/formatter/feature_data_format.js.map +1 -0
  36. package/lib/formatter/helpers/constants.d.ts +50 -0
  37. package/lib/formatter/helpers/constants.js +60 -0
  38. package/lib/formatter/helpers/constants.js.map +1 -0
  39. package/lib/formatter/helpers/formatters.js +2 -0
  40. package/lib/formatter/helpers/formatters.js.map +1 -1
  41. package/lib/formatter/helpers/report_generator.d.ts +148 -0
  42. package/lib/formatter/helpers/report_generator.js +590 -0
  43. package/lib/formatter/helpers/report_generator.js.map +1 -0
  44. package/lib/formatter/helpers/test_case_attempt_formatter.js +1 -1
  45. package/lib/formatter/helpers/test_case_attempt_formatter.js.map +1 -1
  46. package/lib/formatter/helpers/upload_serivce.d.ts +26 -0
  47. package/lib/formatter/helpers/upload_serivce.js +237 -0
  48. package/lib/formatter/helpers/upload_serivce.js.map +1 -0
  49. package/lib/formatter/helpers/uploader.d.ts +12 -0
  50. package/lib/formatter/helpers/uploader.js +148 -0
  51. package/lib/formatter/helpers/uploader.js.map +1 -0
  52. package/lib/runtime/test_case_runner.d.ts +1 -0
  53. package/lib/runtime/test_case_runner.js +10 -1
  54. package/lib/runtime/test_case_runner.js.map +1 -1
  55. package/lib/version.d.ts +1 -1
  56. package/lib/version.js +1 -1
  57. package/lib/version.js.map +1 -1
  58. package/package.json +13 -4
@@ -0,0 +1,590 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ var _a, _b;
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ const messages = __importStar(require("@cucumber/messages"));
31
+ const fs_1 = __importDefault(require("fs"));
32
+ const path_1 = __importDefault(require("path"));
33
+ const upload_serivce_1 = require("./upload_serivce");
34
+ const fs_2 = require("fs");
35
+ const URL = process.env.NODE_ENV_BLINQ === 'dev'
36
+ ? 'https://dev.api.blinq.io/api/runs'
37
+ : process.env.NODE_ENV_BLINQ === 'local'
38
+ ? 'http://localhost:5001/api/runs'
39
+ : process.env.NODE_ENV_BLINQ === 'stage'
40
+ ? 'https://stage.api.blinq.io/api/runs'
41
+ : process.env.NODE_ENV_BLINQ === 'prod'
42
+ ? 'https://api.blinq.io/api/runs'
43
+ : !process.env.NODE_ENV_BLINQ
44
+ ? 'https://api.blinq.io/api/runs'
45
+ : `${process.env.NODE_ENV_BLINQ}/api/runs`;
46
+ const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
47
+ const BATCH_SIZE = 10;
48
+ const MAX_RETRIES = 3;
49
+ const REPORT_SERVICE_TOKEN = (_b = process.env.TOKEN) !== null && _b !== void 0 ? _b : process.env.REPORT_SERVICE_TOKEN;
50
+ class ReportGenerator {
51
+ constructor() {
52
+ this.report = {
53
+ result: {
54
+ status: 'UNKNOWN',
55
+ },
56
+ testCases: [],
57
+ env: {
58
+ name: '',
59
+ baseUrl: '',
60
+ },
61
+ };
62
+ this.gherkinDocumentMap = new Map();
63
+ this.stepMap = new Map();
64
+ this.pickleMap = new Map();
65
+ this.testCaseMap = new Map();
66
+ this.testStepMap = new Map();
67
+ this.stepReportMap = new Map();
68
+ this.testCaseReportMap = new Map();
69
+ this.scenarioIterationCountMap = new Map();
70
+ this.logs = [];
71
+ this.networkLog = [];
72
+ this.stepLogs = [];
73
+ this.stepNetworkLogs = [];
74
+ this.runName = '';
75
+ this.ariaSnapshot = '';
76
+ this.initialAriaSnapshot = '';
77
+ this.reportFolder = null;
78
+ this.uploadService = new upload_serivce_1.RunUploadService(REPORT_SERVICE_URL, REPORT_SERVICE_TOKEN);
79
+ }
80
+ async handleMessage(envelope, reRunId) {
81
+ if (envelope.meta && 'runName' in envelope.meta) {
82
+ this.runName = envelope.meta.runName;
83
+ }
84
+ const type = Object.keys(envelope)[0];
85
+ switch (type) {
86
+ // case "meta": { break}
87
+ // case "source": { break}
88
+ case 'parseError': {
89
+ const parseError = envelope[type];
90
+ this.handleParseError(parseError);
91
+ break;
92
+ }
93
+ case 'gherkinDocument': {
94
+ const doc = envelope[type];
95
+ this.onGherkinDocument(doc);
96
+ break;
97
+ }
98
+ case 'pickle': {
99
+ const pickle = envelope[type];
100
+ this.onPickle(pickle);
101
+ break;
102
+ }
103
+ // case "stepDefinition": { break}
104
+ // case "hook": { break} // Before Hook
105
+ case 'testRunStarted': {
106
+ const testRunStarted = envelope[type];
107
+ this.onTestRunStarted(testRunStarted);
108
+ break;
109
+ }
110
+ case 'testCase': {
111
+ const testCase = envelope[type];
112
+ this.onTestCase(testCase);
113
+ break;
114
+ }
115
+ case 'testCaseStarted': {
116
+ const testCaseStarted = envelope[type];
117
+ this.onTestCaseStarted(testCaseStarted);
118
+ break;
119
+ }
120
+ case 'testStepStarted': {
121
+ const testStepStarted = envelope[type];
122
+ this.onTestStepStarted(testStepStarted);
123
+ break;
124
+ }
125
+ case 'attachment': {
126
+ const attachment = envelope[type];
127
+ this.onAttachment(attachment);
128
+ break;
129
+ }
130
+ case 'testStepFinished': {
131
+ const testStepFinished = envelope[type];
132
+ this.onTestStepFinished(testStepFinished);
133
+ break;
134
+ }
135
+ case 'testCaseFinished': {
136
+ const testCaseFinished = envelope[type];
137
+ return await this.onTestCaseFinished(testCaseFinished, reRunId);
138
+ }
139
+ // case "hook": { break} // After Hook
140
+ case 'testRunFinished': {
141
+ const testRunFinished = envelope[type];
142
+ this.onTestRunFinished(testRunFinished);
143
+ break;
144
+ }
145
+ // case "parameterType" : { break}
146
+ // case "undefinedParameterType": { break}
147
+ }
148
+ }
149
+ getReport() {
150
+ return this.report;
151
+ }
152
+ handleParseError(parseError) {
153
+ const { message } = parseError;
154
+ const timestamp = new Date().getTime();
155
+ this.report.result = {
156
+ status: 'FAILED',
157
+ startTime: timestamp,
158
+ endTime: timestamp,
159
+ message: message,
160
+ };
161
+ }
162
+ onGherkinDocument(doc) {
163
+ this.gherkinDocumentMap.set(doc.uri, doc);
164
+ doc.feature.children.forEach((child) => {
165
+ if (child.scenario) {
166
+ child.scenario.steps.forEach((step) => {
167
+ this.stepMap.set(step.id, step);
168
+ });
169
+ }
170
+ else if (child.background) {
171
+ child.background.steps.forEach((step) => {
172
+ this.stepMap.set(step.id, step);
173
+ });
174
+ }
175
+ else if (child.rule) {
176
+ child.rule.children.forEach((child) => {
177
+ if (child.scenario) {
178
+ child.scenario.steps.forEach((step) => {
179
+ this.stepMap.set(step.id, step);
180
+ });
181
+ }
182
+ else if (child.background) {
183
+ child.background.steps.forEach((step) => {
184
+ this.stepMap.set(step.id, step);
185
+ });
186
+ }
187
+ });
188
+ }
189
+ });
190
+ }
191
+ onPickle(pickle) {
192
+ this.pickleMap.set(pickle.id, pickle);
193
+ }
194
+ getTimeStamp(timestamp) {
195
+ return timestamp.seconds * 1000 + timestamp.nanos / 1000000;
196
+ }
197
+ onTestRunStarted(testRunStarted) {
198
+ this.report.result = {
199
+ status: 'STARTED',
200
+ startTime: this.getTimeStamp(testRunStarted.timestamp),
201
+ };
202
+ }
203
+ onTestCase(testCase) {
204
+ this.testCaseMap.set(testCase.id, testCase);
205
+ testCase.testSteps.forEach((testStep) => {
206
+ this.testStepMap.set(testStep.id, testStep);
207
+ });
208
+ }
209
+ _findScenario(doc, scenarioId) {
210
+ for (const child of doc.feature.children) {
211
+ if (child.scenario && child.scenario.id === scenarioId) {
212
+ return child.scenario;
213
+ }
214
+ if (child.rule) {
215
+ for (const scenario of child.rule.children) {
216
+ if (scenario.scenario && scenario.scenario.id === scenarioId) {
217
+ return scenario.scenario;
218
+ }
219
+ }
220
+ }
221
+ }
222
+ throw new Error(`scenario "${scenarioId}" not found`);
223
+ }
224
+ _getParameters(scenario, exampleId) {
225
+ const parameters = {};
226
+ if (scenario.examples.length === 0)
227
+ return parameters;
228
+ for (const examples of scenario.examples) {
229
+ for (const tableRow of examples.tableBody) {
230
+ if (tableRow.id === exampleId) {
231
+ for (let i = 0; i < examples.tableHeader.cells.length; i++) {
232
+ parameters[examples.tableHeader.cells[i].value] =
233
+ tableRow.cells[i].value;
234
+ }
235
+ }
236
+ }
237
+ }
238
+ return parameters;
239
+ }
240
+ onTestCaseStarted(testCaseStarted) {
241
+ const { testCaseId, id, timestamp } = testCaseStarted;
242
+ const testCase = this.testCaseMap.get(testCaseId);
243
+ if (testCase === undefined)
244
+ throw new Error(`testCase with id ${testCaseId} not found`);
245
+ const pickle = this.pickleMap.get(testCase.pickleId);
246
+ if (pickle === undefined)
247
+ throw new Error(`pickle with id ${testCase.pickleId} not found`);
248
+ const doc = this.gherkinDocumentMap.get(pickle.uri);
249
+ if (doc === undefined)
250
+ throw new Error(`gherkinDocument with uri ${pickle.uri} not found`);
251
+ const featureName = doc.feature.name;
252
+ const scenarioId = pickle.astNodeIds[0];
253
+ const scenario = this._findScenario(doc, scenarioId);
254
+ const scenarioName = scenario.name;
255
+ if (!this.scenarioIterationCountMap.has(scenarioId)) {
256
+ this.scenarioIterationCountMap.set(scenarioId, 1);
257
+ }
258
+ const parameters = this._getParameters(scenario, pickle.astNodeIds[1]);
259
+ console.log(`Running scenario ${scenarioName} iteration ${this.scenarioIterationCountMap.get(scenarioId)} with parameters:\n${JSON.stringify(parameters, null, 4)}\n
260
+ `);
261
+ this.scenarioIterationCountMap.set(scenarioId, this.scenarioIterationCountMap.get(scenarioId) + 1);
262
+ const steps = pickle.steps.map((pickleStep) => {
263
+ const stepId = pickleStep.astNodeIds[0];
264
+ const step = this.stepMap.get(stepId);
265
+ this.stepReportMap.set(pickleStep.id, {
266
+ type: step.keywordType,
267
+ keyword: step.keyword,
268
+ text: step.text,
269
+ commands: [],
270
+ result: {
271
+ status: 'UNKNOWN',
272
+ },
273
+ networkData: [],
274
+ webLog: [],
275
+ data: {},
276
+ ariaSnapshot: this.ariaSnapshot,
277
+ });
278
+ return this.stepReportMap.get(pickleStep.id);
279
+ });
280
+ this.testCaseReportMap.set(id, {
281
+ id,
282
+ uri: pickle.uri,
283
+ featureName,
284
+ scenarioName,
285
+ parameters,
286
+ steps,
287
+ result: {
288
+ status: 'STARTED',
289
+ startTime: this.getTimeStamp(timestamp),
290
+ },
291
+ webLog: [],
292
+ networkLog: [],
293
+ env: {
294
+ name: this.report.env.name,
295
+ baseUrl: this.report.env.baseUrl,
296
+ },
297
+ });
298
+ this.report.testCases.push(this.testCaseReportMap.get(id));
299
+ }
300
+ onTestStepStarted(testStepStarted) {
301
+ const { testStepId, timestamp } = testStepStarted;
302
+ const testStep = this.testStepMap.get(testStepId);
303
+ if (testStep === undefined)
304
+ throw new Error(`testStep with id ${testStepId} not found`);
305
+ if (testStep.pickleStepId === undefined)
306
+ return;
307
+ const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
308
+ stepProgess.result = {
309
+ status: 'STARTED',
310
+ startTime: this.getTimeStamp(timestamp),
311
+ };
312
+ }
313
+ onAttachment(attachment) {
314
+ const { testStepId, body, mediaType } = attachment;
315
+ if (mediaType === 'text/plain') {
316
+ this.reportFolder = body.replaceAll('\\', '/');
317
+ return;
318
+ }
319
+ if (mediaType === 'application/json+snapshot-before') {
320
+ this.initialAriaSnapshot = body;
321
+ return;
322
+ }
323
+ if (mediaType === 'application/json+snapshot-after') {
324
+ this.ariaSnapshot = body;
325
+ return;
326
+ }
327
+ if (mediaType === 'application/json+env') {
328
+ const data = JSON.parse(body);
329
+ this.report.env = data;
330
+ this.report.testCases.map((testCase) => {
331
+ testCase.env = data;
332
+ return testCase;
333
+ });
334
+ }
335
+ if (mediaType === 'application/json+log') {
336
+ const log = JSON.parse(body);
337
+ if (this.logs.length < 1000) {
338
+ this.logs.push(log);
339
+ this.stepLogs.push(log);
340
+ }
341
+ }
342
+ if (mediaType === 'application/json+network') {
343
+ const networkLog = JSON.parse(body);
344
+ if (this.networkLog.length < 1000)
345
+ this.networkLog.push(networkLog);
346
+ this.stepNetworkLogs.push(networkLog);
347
+ }
348
+ const testStep = this.testStepMap.get(testStepId);
349
+ if (testStep.pickleStepId === undefined)
350
+ return;
351
+ const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
352
+ if (mediaType === 'application/json') {
353
+ const command = JSON.parse(body);
354
+ stepProgess.commands.push(command);
355
+ }
356
+ }
357
+ getFailedTestStepResult({ commands, startTime, endTime, result, }) {
358
+ for (const command of commands) {
359
+ if (command.result.status === 'FAILED') {
360
+ return {
361
+ status: 'FAILED',
362
+ message: command.result.message,
363
+ startTime,
364
+ endTime,
365
+ };
366
+ }
367
+ }
368
+ return {
369
+ status: 'FAILED',
370
+ startTime,
371
+ endTime,
372
+ message: result.message,
373
+ };
374
+ }
375
+ onTestStepFinished(testStepFinished) {
376
+ const { testStepId, testStepResult, timestamp } = testStepFinished;
377
+ const testStep = this.testStepMap.get(testStepId);
378
+ if (testStep.pickleStepId === undefined) {
379
+ if (testStepResult.status === 'FAILED') {
380
+ console.error(`Before/After hook failed with message: ${testStepResult.message}`);
381
+ }
382
+ return;
383
+ }
384
+ if (testStepResult.status === 'UNDEFINED') {
385
+ const step = this.stepReportMap.get(testStep.pickleStepId);
386
+ const stepName = step ? step.keyword + ' ' + step.text : 'Undefined step';
387
+ const undefinedCommand = {
388
+ testStepId: testStepId,
389
+ body: JSON.stringify({
390
+ type: 'error',
391
+ text: 'Undefined step: ' + stepName,
392
+ result: {
393
+ status: 'FAILED',
394
+ startTime: this.getTimeStamp(timestamp),
395
+ endTime: this.getTimeStamp(timestamp),
396
+ },
397
+ }),
398
+ mediaType: 'application/json',
399
+ contentEncoding: messages.AttachmentContentEncoding.IDENTITY,
400
+ };
401
+ this.onAttachment(undefinedCommand);
402
+ }
403
+ const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
404
+ const prevStepResult = stepProgess.result;
405
+ let data = {};
406
+ try {
407
+ const reportFolder = this.reportFolder;
408
+ if (reportFolder === null) {
409
+ throw new Error('"reportFolder" is "null". Failed to run BVT hooks. Please retry after running "Generate All" or "Record Scenario" ');
410
+ }
411
+ if (fs_1.default.existsSync(path_1.default.join(reportFolder, 'data.json'))) {
412
+ data = JSON.parse(fs_1.default.readFileSync(path_1.default.join(reportFolder, 'data.json'), 'utf8'));
413
+ }
414
+ }
415
+ catch (error) {
416
+ console.log('Error reading data.json');
417
+ }
418
+ if (testStepResult.status === 'FAILED') {
419
+ stepProgess.result = this.getFailedTestStepResult({
420
+ commands: stepProgess.commands,
421
+ startTime: prevStepResult.startTime,
422
+ endTime: this.getTimeStamp(timestamp),
423
+ result: testStepResult,
424
+ });
425
+ }
426
+ else {
427
+ stepProgess.result = {
428
+ status: testStepResult.status,
429
+ startTime: prevStepResult.startTime,
430
+ endTime: this.getTimeStamp(timestamp),
431
+ };
432
+ }
433
+ stepProgess.webLog = this.stepLogs;
434
+ stepProgess.networkData = this.stepNetworkLogs;
435
+ stepProgess.ariaSnapshot = this.ariaSnapshot;
436
+ this.ariaSnapshot = '';
437
+ this.stepNetworkLogs = [];
438
+ this.stepLogs = [];
439
+ if (Object.keys(data).length > 0) {
440
+ stepProgess.data = data;
441
+ }
442
+ }
443
+ getLogFileContent() {
444
+ let projectPath = process.cwd();
445
+ if (process.env.PROJECT_PATH) {
446
+ projectPath = process.env.PROJECT_PATH;
447
+ }
448
+ const logFolder = path_1.default.join(projectPath, 'logs', 'web');
449
+ if (!fs_1.default.existsSync(logFolder)) {
450
+ return [];
451
+ }
452
+ let nextId = 1;
453
+ while (fs_1.default.existsSync(path_1.default.join(logFolder, `${nextId}.json`))) {
454
+ nextId++;
455
+ }
456
+ if (nextId === 1) {
457
+ return [];
458
+ }
459
+ try {
460
+ const logFileContent = fs_1.default.readFileSync(path_1.default.join(logFolder, `${nextId - 1}.json`), 'utf8');
461
+ return JSON.parse(logFileContent);
462
+ }
463
+ catch (error) {
464
+ return [];
465
+ }
466
+ }
467
+ getTestCaseResult(steps) {
468
+ for (const step of steps) {
469
+ switch (step.result.status) {
470
+ case 'FAILED':
471
+ return {
472
+ status: step.result.status,
473
+ message: step.result.message,
474
+ // exception: step.result.exception,
475
+ };
476
+ case 'AMBIGUOUS':
477
+ case 'UNDEFINED':
478
+ case 'PENDING':
479
+ return {
480
+ status: 'FAILED',
481
+ message: `step "${step.text}" is ${step.result.status}`,
482
+ };
483
+ }
484
+ }
485
+ return {
486
+ status: 'PASSED',
487
+ };
488
+ }
489
+ async onTestCaseFinished(testCaseFinished, reRunId) {
490
+ const { testCaseStartedId, timestamp } = testCaseFinished;
491
+ const testProgress = this.testCaseReportMap.get(testCaseStartedId);
492
+ const prevResult = testProgress.result;
493
+ const steps = Object.values(testProgress.steps);
494
+ const result = this.getTestCaseResult(steps);
495
+ const endTime = this.getTimeStamp(timestamp);
496
+ testProgress.result = {
497
+ ...result,
498
+ startTime: prevResult.startTime,
499
+ endTime,
500
+ };
501
+ testProgress.webLog = this.logs;
502
+ testProgress.networkLog = this.networkLog;
503
+ testProgress.initialAriaSnapshot = this.initialAriaSnapshot;
504
+ this.initialAriaSnapshot = '';
505
+ this.networkLog = [];
506
+ this.logs = [];
507
+ if (process.env.TESTCASE_REPORT_FOLDER_PATH) {
508
+ this.reportFolder = process.env.TESTCASE_REPORT_FOLDER_PATH;
509
+ if (!fs_1.default.existsSync(this.reportFolder)) {
510
+ fs_1.default.mkdirSync(this.reportFolder);
511
+ }
512
+ const reportFilePath = path_1.default.join(this.reportFolder, `${endTime}_${testProgress.scenarioName}.json`);
513
+ (0, fs_2.writeFileSync)(reportFilePath, JSON.stringify(testProgress, null, 2));
514
+ return undefined;
515
+ }
516
+ else {
517
+ return await this.uploadTestCase(testProgress, reRunId);
518
+ }
519
+ }
520
+ async uploadTestCase(testCase, rerunId) {
521
+ let runId = '';
522
+ let projectId = '';
523
+ if (!process.env.UPLOADING_TEST_CASE) {
524
+ process.env.UPLOADING_TEST_CASE = '[]';
525
+ }
526
+ const anyRemArr = JSON.parse(process.env.UPLOADING_TEST_CASE);
527
+ const randomID = Math.random().toString(36).substring(7);
528
+ anyRemArr.push(randomID);
529
+ let data;
530
+ process.env.UPLOADING_TEST_CASE = JSON.stringify(anyRemArr);
531
+ try {
532
+ if (process.env.RUN_ID &&
533
+ process.env.PROJECT_ID &&
534
+ !process.env.IGNORE_ENV_VARIABLES) {
535
+ runId = process.env.RUN_ID;
536
+ projectId = process.env.PROJECT_ID;
537
+ }
538
+ else {
539
+ const runDoc = await this.uploadService.createRunDocument(this.runName);
540
+ runId = runDoc._id;
541
+ projectId = runDoc.project_id;
542
+ if (!process.env.IGNORE_ENV_VARIABLES) {
543
+ process.env.RUN_ID = runId;
544
+ process.env.PROJECT_ID = projectId;
545
+ }
546
+ }
547
+ data = await this.uploadService.uploadTestCase(testCase, runId, projectId, this.reportFolder, rerunId);
548
+ this.writeTestCaseReportToDisk(testCase);
549
+ }
550
+ catch (e) {
551
+ console.error('Error uploading test case:', e);
552
+ }
553
+ finally {
554
+ const arrRem = JSON.parse(process.env.UPLOADING_TEST_CASE);
555
+ arrRem.splice(arrRem.indexOf(randomID), 1);
556
+ process.env.UPLOADING_TEST_CASE = JSON.stringify(arrRem);
557
+ }
558
+ return data ? data : null;
559
+ }
560
+ writeTestCaseReportToDisk(testCase) {
561
+ try {
562
+ let i = 0;
563
+ while (fs_1.default.existsSync(path_1.default.join(this.reportFolder, `${i}`))) {
564
+ i++;
565
+ }
566
+ fs_1.default.mkdirSync(path_1.default.join(this.reportFolder, `${i}`));
567
+ //exclude network log from the saved report
568
+ const networkLog = testCase.networkLog;
569
+ delete testCase.networkLog;
570
+ fs_1.default.writeFileSync(path_1.default.join(this.reportFolder, `${i}`, `report.json`), JSON.stringify(testCase, null, 2));
571
+ fs_1.default.writeFileSync(path_1.default.join(this.reportFolder, `${i}`, `network.json`), JSON.stringify(networkLog, null, 2));
572
+ }
573
+ catch (error) {
574
+ console.error('Error writing test case report to disk:', error);
575
+ }
576
+ }
577
+ onTestRunFinished(testRunFinished) {
578
+ const { timestamp, success, message } = testRunFinished;
579
+ const prevResult = this.report.result;
580
+ this.report.result = {
581
+ status: success ? 'PASSED' : 'FAILED',
582
+ startTime: prevResult.startTime,
583
+ endTime: this.getTimeStamp(timestamp),
584
+ message,
585
+ // exception,
586
+ };
587
+ }
588
+ }
589
+ exports.default = ReportGenerator;
590
+ //# sourceMappingURL=report_generator.js.map