@reportportal/client-javascript 5.0.2 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -18
- package/LICENSE.txt +200 -200
- package/README.md +310 -297
- package/VERSION +1 -1
- package/analytics/analytics.js +15 -15
- package/analytics/constants.js +7 -7
- package/analytics/events.js +16 -16
- package/lib/constants/events.js +7 -7
- package/lib/constants/statuses.js +12 -12
- package/lib/helpers.js +85 -85
- package/lib/publicReportingAPI.js +92 -92
- package/lib/report-portal-client.js +719 -711
- package/lib/rest.js +98 -60
- package/package.json +65 -60
- package/.eslintrc +0 -17
- package/.idea/client-javascript.iml +0 -12
- package/.idea/codeStyles/Project.xml +0 -22
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/copyright/APACHE_2_0.xml +0 -6
- package/.idea/copyright/profiles_settings.xml +0 -3
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -571
- package/.istanbul.yml +0 -3
- package/spec/analytics.spec.js +0 -46
- package/spec/helper.spec.js +0 -142
- package/spec/publicReportingAPI.spec.js +0 -75
- package/spec/report-portal-client.spec.js +0 -730
- package/spec/rest.spec.js +0 -287
- package/spec/support/jasmine.json +0 -11
- package/version_fragment +0 -1
|
@@ -1,711 +1,719 @@
|
|
|
1
|
-
/* eslint-disable quotes,no-console,class-methods-use-this */
|
|
2
|
-
const UniqId = require('uniqid');
|
|
3
|
-
const { URLSearchParams } = require('url');
|
|
4
|
-
const helpers = require('./helpers');
|
|
5
|
-
const RestClient = require('./rest');
|
|
6
|
-
const Analytics = require('../analytics/analytics');
|
|
7
|
-
const { RP_STATUSES } = require('./constants/statuses');
|
|
8
|
-
const { CLIENT_JAVASCRIPT_EVENTS, getAgentEventLabel } = require('
|
|
9
|
-
|
|
10
|
-
const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();
|
|
11
|
-
|
|
12
|
-
class RPClient {
|
|
13
|
-
|
|
14
|
-
* Create a client for RP.
|
|
15
|
-
* @param {Object} params - config object.
|
|
16
|
-
* params should look like this
|
|
17
|
-
* {
|
|
18
|
-
* token: "00000000-0000-0000-0000-000000000000",
|
|
19
|
-
* endpoint: "http://localhost:8080/api/v1",
|
|
20
|
-
* launch: "YOUR LAUNCH NAME",
|
|
21
|
-
* project: "PROJECT NAME",
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} agentParams - agent's info object.
|
|
25
|
-
* agentParams should look like this
|
|
26
|
-
* {
|
|
27
|
-
* name: "AGENT NAME",
|
|
28
|
-
* version: "AGENT VERSION",
|
|
29
|
-
* }
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
*
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
"
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* has been sent
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
* Finish launch.
|
|
214
|
-
* @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
|
|
215
|
-
* @param {Object} finishExecutionRQ - finish launch info should include time and status.
|
|
216
|
-
* finishExecutionRQ should look like this
|
|
217
|
-
* {
|
|
218
|
-
* "endTime": this.helper.now(),
|
|
219
|
-
* "status": "passed" or one of ‘passed’, ‘failed’, ‘stopped’, ‘skipped’, ‘interrupted’, ‘cancelled’
|
|
220
|
-
* }
|
|
221
|
-
* @Returns {Object} - an object which contains a tempID and a promise
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
* This method is used to create data object for merge request to ReportPortal.
|
|
262
|
-
*
|
|
263
|
-
* @Returns {Object} - an object which contains a data for merge launches in ReportPortal.
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
* This method is used for merge launches in ReportPortal.
|
|
280
|
-
*
|
|
281
|
-
* Please, keep in mind that this method is work only in case
|
|
282
|
-
* the option isLaunchMergeRequired is true.
|
|
283
|
-
*/
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
* This method is used for frameworks as Jasmine. There is problem when
|
|
317
|
-
* it doesn't wait for promise resolve and stop the process. So it better to call
|
|
318
|
-
* this method at the spec's function as @afterAll() and manually resolve this promise.
|
|
319
|
-
*
|
|
320
|
-
* @return Promise
|
|
321
|
-
*/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
*
|
|
330
|
-
* @param {
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
|
|
334
|
-
"
|
|
335
|
-
"
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
"
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
"
|
|
384
|
-
"
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
'
|
|
397
|
-
'
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
* @
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
"
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
*
|
|
583
|
-
* {
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
*
|
|
617
|
-
* {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
|
|
1
|
+
/* eslint-disable quotes,no-console,class-methods-use-this */
|
|
2
|
+
const UniqId = require('uniqid');
|
|
3
|
+
const { URLSearchParams } = require('url');
|
|
4
|
+
const helpers = require('./helpers');
|
|
5
|
+
const RestClient = require('./rest');
|
|
6
|
+
const Analytics = require('../analytics/analytics');
|
|
7
|
+
const { RP_STATUSES } = require('./constants/statuses');
|
|
8
|
+
const { CLIENT_JAVASCRIPT_EVENTS, getAgentEventLabel } = require('../analytics/events');
|
|
9
|
+
|
|
10
|
+
const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();
|
|
11
|
+
|
|
12
|
+
class RPClient {
|
|
13
|
+
/**
|
|
14
|
+
* Create a client for RP.
|
|
15
|
+
* @param {Object} params - config object.
|
|
16
|
+
* params should look like this
|
|
17
|
+
* {
|
|
18
|
+
* token: "00000000-0000-0000-0000-000000000000",
|
|
19
|
+
* endpoint: "http://localhost:8080/api/v1",
|
|
20
|
+
* launch: "YOUR LAUNCH NAME",
|
|
21
|
+
* project: "PROJECT NAME",
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} agentParams - agent's info object.
|
|
25
|
+
* agentParams should look like this
|
|
26
|
+
* {
|
|
27
|
+
* name: "AGENT NAME",
|
|
28
|
+
* version: "AGENT VERSION",
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
constructor(params, agentParams) {
|
|
32
|
+
this.debug = params.debug;
|
|
33
|
+
this.isLaunchMergeRequired = params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired;
|
|
34
|
+
this.map = {};
|
|
35
|
+
this.baseURL = [params.endpoint, params.project].join('/');
|
|
36
|
+
const headers = {
|
|
37
|
+
'User-Agent': 'NodeJS',
|
|
38
|
+
Authorization: `bearer ${params.token}`,
|
|
39
|
+
...(params.headers || {}),
|
|
40
|
+
};
|
|
41
|
+
this.headers = headers;
|
|
42
|
+
this.token = params.token;
|
|
43
|
+
this.config = params;
|
|
44
|
+
this.helpers = helpers;
|
|
45
|
+
this.restClient = new RestClient({
|
|
46
|
+
baseURL: this.baseURL,
|
|
47
|
+
headers: this.headers,
|
|
48
|
+
restClientConfig: params.restClientConfig,
|
|
49
|
+
});
|
|
50
|
+
this.analytics = new Analytics(agentParams);
|
|
51
|
+
this.launchUuid = '';
|
|
52
|
+
this.nonRetriedItemMap = new Map();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line valid-jsdoc
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @Private
|
|
59
|
+
*/
|
|
60
|
+
logDebug(msg) {
|
|
61
|
+
if (this.debug) {
|
|
62
|
+
console.log(msg);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
calculateNonRetriedItemMapKey(launchId, parentId, name, itemId = '') {
|
|
67
|
+
return `${launchId}__${parentId}__${name}__${itemId}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getUniqId() {
|
|
71
|
+
return UniqId();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getRejectAnswer(tempId, error) {
|
|
75
|
+
return {
|
|
76
|
+
tempId,
|
|
77
|
+
promise: Promise.reject(error),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getNewItemObj(startPromiseFunc) {
|
|
82
|
+
let resolveFinish;
|
|
83
|
+
let rejectFinish;
|
|
84
|
+
const obj = {
|
|
85
|
+
promiseStart: (new Promise(startPromiseFunc)),
|
|
86
|
+
realId: '',
|
|
87
|
+
children: [],
|
|
88
|
+
finishSend: false,
|
|
89
|
+
promiseFinish: (new Promise((resolve, reject) => {
|
|
90
|
+
resolveFinish = resolve;
|
|
91
|
+
rejectFinish = reject;
|
|
92
|
+
})),
|
|
93
|
+
};
|
|
94
|
+
obj.resolveFinish = resolveFinish;
|
|
95
|
+
obj.rejectFinish = rejectFinish;
|
|
96
|
+
return obj;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line valid-jsdoc
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @Private
|
|
103
|
+
*/
|
|
104
|
+
cleanMap(ids) {
|
|
105
|
+
ids.forEach((id) => {
|
|
106
|
+
delete this.map[id];
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
checkConnect() {
|
|
111
|
+
const url = [this.config.endpoint.replace('/v2', '/v1'), 'user'].join('/');
|
|
112
|
+
return RestClient.request('GET', url, {}, { headers: this.headers });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
triggerAnalyticsEvent() {
|
|
116
|
+
if (process.env.REPORTPORTAL_CLIENT_JS_NO_ANALYTICS) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (this.analytics.agentParams) {
|
|
121
|
+
const label = getAgentEventLabel(this.analytics.agentParams);
|
|
122
|
+
this.analytics.trackEvent(Object.assign(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label }));
|
|
123
|
+
} else {
|
|
124
|
+
this.analytics.trackEvent(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Start launch and report it.
|
|
130
|
+
* @param {Object} launchDataRQ - request object.
|
|
131
|
+
* launchDataRQ should look like this
|
|
132
|
+
* {
|
|
133
|
+
"description": "string" (support markdown),
|
|
134
|
+
"mode": "DEFAULT" or "DEBUG",
|
|
135
|
+
"name": "string",
|
|
136
|
+
"startTime": this.helper.now(),
|
|
137
|
+
"attributes": [
|
|
138
|
+
{
|
|
139
|
+
"key": "string",
|
|
140
|
+
"value": "string"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"value": "string"
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
* }
|
|
147
|
+
* @Returns an object which contains a tempID and a promise
|
|
148
|
+
*
|
|
149
|
+
* As system attributes, this method sends the following data (these data are not for public use):
|
|
150
|
+
* client name, version;
|
|
151
|
+
* agent name, version (if given);
|
|
152
|
+
* browser name, version (if given);
|
|
153
|
+
* OS type, architecture;
|
|
154
|
+
* RAMSize;
|
|
155
|
+
* nodeJS version;
|
|
156
|
+
*
|
|
157
|
+
* This method works in two ways:
|
|
158
|
+
* First - If launchDataRQ object doesn't contain ID field,
|
|
159
|
+
* it would create a new Launch instance at the Report Portal with it ID.
|
|
160
|
+
* Second - If launchDataRQ would contain ID field,
|
|
161
|
+
* client would connect to the existing Launch which ID
|
|
162
|
+
* has been sent , and would send all data to it.
|
|
163
|
+
* Notice that Launch which ID has been sent must be 'IN PROGRESS' state at the Report Portal
|
|
164
|
+
* or it would throw an error.
|
|
165
|
+
* @Returns {Object} - an object which contains a tempID and a promise
|
|
166
|
+
*/
|
|
167
|
+
startLaunch(launchDataRQ) {
|
|
168
|
+
const tempId = this.getUniqId();
|
|
169
|
+
|
|
170
|
+
if (launchDataRQ.id) {
|
|
171
|
+
this.map[tempId] = this.getNewItemObj((resolve) => resolve(launchDataRQ));
|
|
172
|
+
this.map[tempId].realId = launchDataRQ.id;
|
|
173
|
+
this.launchUuid = launchDataRQ.id;
|
|
174
|
+
} else {
|
|
175
|
+
const systemAttr = helpers.getSystemAttribute();
|
|
176
|
+
const attributes = Array.isArray(launchDataRQ.attributes)
|
|
177
|
+
? launchDataRQ.attributes.concat(systemAttr)
|
|
178
|
+
: systemAttr;
|
|
179
|
+
const launchData = {
|
|
180
|
+
name: this.config.launch || 'Test launch name',
|
|
181
|
+
startTime: this.helpers.now(),
|
|
182
|
+
...launchDataRQ,
|
|
183
|
+
attributes,
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
|
|
187
|
+
const url = 'launch';
|
|
188
|
+
this.logDebug(`Start launch ${tempId}`);
|
|
189
|
+
this.restClient.create(url, launchData, { headers: this.headers })
|
|
190
|
+
.then((response) => {
|
|
191
|
+
this.map[tempId].realId = response.id;
|
|
192
|
+
this.launchUuid = response.id;
|
|
193
|
+
|
|
194
|
+
if (this.isLaunchMergeRequired) {
|
|
195
|
+
helpers.saveLaunchIdToFile(response.id);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
resolve(response);
|
|
199
|
+
}, (error) => {
|
|
200
|
+
console.dir(error);
|
|
201
|
+
reject(error);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
this.triggerAnalyticsEvent();
|
|
206
|
+
return {
|
|
207
|
+
tempId,
|
|
208
|
+
promise: this.map[tempId].promiseStart,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Finish launch.
|
|
214
|
+
* @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
|
|
215
|
+
* @param {Object} finishExecutionRQ - finish launch info should include time and status.
|
|
216
|
+
* finishExecutionRQ should look like this
|
|
217
|
+
* {
|
|
218
|
+
* "endTime": this.helper.now(),
|
|
219
|
+
* "status": "passed" or one of ‘passed’, ‘failed’, ‘stopped’, ‘skipped’, ‘interrupted’, ‘cancelled’
|
|
220
|
+
* }
|
|
221
|
+
* @Returns {Object} - an object which contains a tempID and a promise
|
|
222
|
+
*/
|
|
223
|
+
finishLaunch(launchTempId, finishExecutionRQ) {
|
|
224
|
+
const launchObj = this.map[launchTempId];
|
|
225
|
+
if (!launchObj) {
|
|
226
|
+
return this.getRejectAnswer(launchTempId, new Error(`Launch "${launchTempId}" not found`));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const finishExecutionData = { endTime: this.helpers.now(), ...finishExecutionRQ };
|
|
230
|
+
|
|
231
|
+
launchObj.finishSend = true;
|
|
232
|
+
Promise.all(launchObj.children.map((itemId) => this.map[itemId].promiseFinish))
|
|
233
|
+
.then(() => {
|
|
234
|
+
launchObj.promiseStart
|
|
235
|
+
.then(() => {
|
|
236
|
+
this.logDebug(`Finish launch ${launchTempId}`);
|
|
237
|
+
const url = ['launch', launchObj.realId, 'finish'].join('/');
|
|
238
|
+
this.restClient.update(url, finishExecutionData, { headers: this.headers })
|
|
239
|
+
.then((response) => {
|
|
240
|
+
this.logDebug(`Success finish launch ${launchTempId}`);
|
|
241
|
+
launchObj.resolveFinish(response);
|
|
242
|
+
}, (error) => {
|
|
243
|
+
this.logDebug(`Error finish launch ${launchTempId}`);
|
|
244
|
+
console.dir(error);
|
|
245
|
+
launchObj.rejectFinish(error);
|
|
246
|
+
});
|
|
247
|
+
}, (error) => {
|
|
248
|
+
launchObj.rejectFinish(error);
|
|
249
|
+
});
|
|
250
|
+
}, (error) => {
|
|
251
|
+
launchObj.rejectFinish(error);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
tempId: launchTempId,
|
|
256
|
+
promise: launchObj.promiseFinish,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/*
|
|
261
|
+
* This method is used to create data object for merge request to ReportPortal.
|
|
262
|
+
*
|
|
263
|
+
* @Returns {Object} - an object which contains a data for merge launches in ReportPortal.
|
|
264
|
+
*/
|
|
265
|
+
getMergeLaunchesRequest(launchIds) {
|
|
266
|
+
return {
|
|
267
|
+
description: "Merged launch",
|
|
268
|
+
endTime: this.helpers.now(),
|
|
269
|
+
extendSuitesDescription: true,
|
|
270
|
+
launches: launchIds,
|
|
271
|
+
mergeType: "BASIC",
|
|
272
|
+
mode: "DEFAULT",
|
|
273
|
+
name: this.config.launch || 'Test launch name',
|
|
274
|
+
attributes: this.config.attributes,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/*
|
|
279
|
+
* This method is used for merge launches in ReportPortal.
|
|
280
|
+
*
|
|
281
|
+
* Please, keep in mind that this method is work only in case
|
|
282
|
+
* the option isLaunchMergeRequired is true.
|
|
283
|
+
*/
|
|
284
|
+
mergeLaunches() {
|
|
285
|
+
if (this.isLaunchMergeRequired) {
|
|
286
|
+
const launchUUIds = helpers.readLaunchesFromFile();
|
|
287
|
+
const params = new URLSearchParams({
|
|
288
|
+
'filter.in.uuid': launchUUIds,
|
|
289
|
+
});
|
|
290
|
+
const launchSearchUrl = `launch?${params.toString()}`;
|
|
291
|
+
return this.restClient.retrieveSyncAPI(launchSearchUrl, { headers: this.headers })
|
|
292
|
+
.then((response) => {
|
|
293
|
+
const launchIds = response.content.map((launch) => launch.id);
|
|
294
|
+
this.logDebug(`Found launches: ${launchIds}`);
|
|
295
|
+
return launchIds;
|
|
296
|
+
}, (error) => {
|
|
297
|
+
console.dir(error);
|
|
298
|
+
})
|
|
299
|
+
.then((launchIds) => {
|
|
300
|
+
const request = this.getMergeLaunchesRequest(launchIds);
|
|
301
|
+
const mergeURL = 'launch/merge';
|
|
302
|
+
return this.restClient.create(mergeURL, request, { headers: this.headers });
|
|
303
|
+
})
|
|
304
|
+
.then(() => {
|
|
305
|
+
this.logDebug(`Launches successfully merged!`);
|
|
306
|
+
})
|
|
307
|
+
.catch((error) => {
|
|
308
|
+
this.logDebug('ERROR');
|
|
309
|
+
this.logDebug(error);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
this.logDebug('Option isLaunchMergeRequired is false');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/*
|
|
316
|
+
* This method is used for frameworks as Jasmine. There is problem when
|
|
317
|
+
* it doesn't wait for promise resolve and stop the process. So it better to call
|
|
318
|
+
* this method at the spec's function as @afterAll() and manually resolve this promise.
|
|
319
|
+
*
|
|
320
|
+
* @return Promise
|
|
321
|
+
*/
|
|
322
|
+
getPromiseFinishAllItems(launchTempId) {
|
|
323
|
+
const launchObj = this.map[launchTempId];
|
|
324
|
+
return Promise.all(launchObj.children.map((itemId) => this.map[itemId].promiseFinish));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Update launch.
|
|
329
|
+
* @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
|
|
330
|
+
* @param {Object} launchData - new launch data
|
|
331
|
+
* launchData should look like this
|
|
332
|
+
* {
|
|
333
|
+
"description": "string" (support markdown),
|
|
334
|
+
"mode": "DEFAULT" or "DEBUG",
|
|
335
|
+
"attributes": [
|
|
336
|
+
{
|
|
337
|
+
"key": "string",
|
|
338
|
+
"value": "string"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"value": "string"
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
}
|
|
345
|
+
* @Returns {Object} - an object which contains a tempId and a promise
|
|
346
|
+
*/
|
|
347
|
+
updateLaunch(launchTempId, launchData) {
|
|
348
|
+
const launchObj = this.map[launchTempId];
|
|
349
|
+
if (!launchObj) {
|
|
350
|
+
return this.getRejectAnswer(launchTempId, new Error(`Launch "${launchTempId}" not found`));
|
|
351
|
+
}
|
|
352
|
+
let resolvePromise;
|
|
353
|
+
let rejectPromise;
|
|
354
|
+
const promise = new Promise((resolve, reject) => {
|
|
355
|
+
resolvePromise = resolve;
|
|
356
|
+
rejectPromise = reject;
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
launchObj.promiseFinish.then(() => {
|
|
360
|
+
const url = ['launch', launchObj.realId, 'update'].join('/');
|
|
361
|
+
this.restClient.update(url, launchData, { headers: this.headers })
|
|
362
|
+
.then((response) => {
|
|
363
|
+
resolvePromise(response);
|
|
364
|
+
}, (error) => {
|
|
365
|
+
rejectPromise(error);
|
|
366
|
+
});
|
|
367
|
+
}, (error) => {
|
|
368
|
+
rejectPromise(error);
|
|
369
|
+
});
|
|
370
|
+
return {
|
|
371
|
+
tempId: launchTempId,
|
|
372
|
+
promise,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* If there is no parentItemId starts Suite, else starts test or item.
|
|
378
|
+
* @param {Object} testItemDataRQ - object with item parameters
|
|
379
|
+
* testItemDataRQ should look like this
|
|
380
|
+
* {
|
|
381
|
+
"description": "string" (support markdown),
|
|
382
|
+
"name": "string",
|
|
383
|
+
"startTime": this.helper.now(),
|
|
384
|
+
"attributes": [
|
|
385
|
+
{
|
|
386
|
+
"key": "string",
|
|
387
|
+
"value": "string"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
"value": "string"
|
|
391
|
+
}
|
|
392
|
+
],
|
|
393
|
+
"type": 'SUITE' or one of 'SUITE', 'STORY', 'TEST',
|
|
394
|
+
'SCENARIO', 'STEP', 'BEFORE_CLASS', 'BEFORE_GROUPS',
|
|
395
|
+
'BEFORE_METHOD', 'BEFORE_SUITE', 'BEFORE_TEST',
|
|
396
|
+
'AFTER_CLASS', 'AFTER_GROUPS', 'AFTER_METHOD',
|
|
397
|
+
'AFTER_SUITE', 'AFTER_TEST'
|
|
398
|
+
}
|
|
399
|
+
* @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
|
|
400
|
+
* @param {string} parentTempId (optional) - temp item id (returned in the query "startTestItem").
|
|
401
|
+
* @Returns {Object} - an object which contains a tempId and a promise
|
|
402
|
+
*/
|
|
403
|
+
startTestItem(testItemDataRQ, launchTempId, parentTempId) {
|
|
404
|
+
let parentMapId = launchTempId;
|
|
405
|
+
const launchObj = this.map[launchTempId];
|
|
406
|
+
if (!launchObj) {
|
|
407
|
+
return this.getRejectAnswer(launchTempId, new Error(`Launch "${launchTempId}" not found`));
|
|
408
|
+
}
|
|
409
|
+
if (launchObj.finishSend) {
|
|
410
|
+
const err = new Error(`Launch "${launchTempId}" is already finished, you can not add an item to it`);
|
|
411
|
+
return this.getRejectAnswer(launchTempId, err);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const testCaseId = testItemDataRQ.testCaseId
|
|
415
|
+
|| helpers.generateTestCaseId(testItemDataRQ.codeRef, testItemDataRQ.parameters);
|
|
416
|
+
const testItemData = { startTime: this.helpers.now(), ...testItemDataRQ, ...(testCaseId && { testCaseId }) };
|
|
417
|
+
|
|
418
|
+
let parentPromise = launchObj.promiseStart;
|
|
419
|
+
if (parentTempId) {
|
|
420
|
+
parentMapId = parentTempId;
|
|
421
|
+
const parentObj = this.map[parentTempId];
|
|
422
|
+
if (!parentObj) {
|
|
423
|
+
return this.getRejectAnswer(launchTempId, new Error(`Item "${parentTempId}" not found`));
|
|
424
|
+
}
|
|
425
|
+
parentPromise = parentObj.promiseStart;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const itemKey = this.calculateNonRetriedItemMapKey(
|
|
429
|
+
launchTempId,
|
|
430
|
+
parentTempId,
|
|
431
|
+
testItemDataRQ.name,
|
|
432
|
+
testItemDataRQ.uniqueId,
|
|
433
|
+
);
|
|
434
|
+
const firstNonRetriedItemPromise = testItemDataRQ.retry && this.nonRetriedItemMap.get(itemKey);
|
|
435
|
+
if (firstNonRetriedItemPromise) {
|
|
436
|
+
parentPromise = Promise.all([parentPromise, firstNonRetriedItemPromise]);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const tempId = this.getUniqId();
|
|
440
|
+
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
|
|
441
|
+
parentPromise.then(() => {
|
|
442
|
+
const realLaunchId = this.map[launchTempId].realId;
|
|
443
|
+
let url = 'item/';
|
|
444
|
+
if (parentTempId) {
|
|
445
|
+
const realParentId = this.map[parentTempId].realId;
|
|
446
|
+
url += `${realParentId}`;
|
|
447
|
+
}
|
|
448
|
+
testItemData.launchUuid = realLaunchId;
|
|
449
|
+
this.logDebug(`Start test item ${tempId}`);
|
|
450
|
+
this.restClient.create(url, testItemData, { headers: this.headers })
|
|
451
|
+
.then((response) => {
|
|
452
|
+
this.logDebug(`Success start item ${tempId}`);
|
|
453
|
+
this.map[tempId].realId = response.id;
|
|
454
|
+
this.nonRetriedItemMap.delete(itemKey);
|
|
455
|
+
resolve(response);
|
|
456
|
+
}, (error) => {
|
|
457
|
+
this.logDebug(`Error start item ${tempId}:`);
|
|
458
|
+
console.dir(error);
|
|
459
|
+
reject(error);
|
|
460
|
+
});
|
|
461
|
+
}, (error) => {
|
|
462
|
+
reject(error);
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
this.map[parentMapId].children.push(tempId);
|
|
466
|
+
|
|
467
|
+
if (!testItemDataRQ.retry) {
|
|
468
|
+
this.nonRetriedItemMap.set(itemKey, this.map[tempId].promiseStart);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return {
|
|
472
|
+
tempId,
|
|
473
|
+
promise: this.map[tempId].promiseStart,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Finish Suite or Step level.
|
|
479
|
+
* @param {string} itemTempId - temp item id (returned in the query "startTestItem").
|
|
480
|
+
* @param {Object} finishTestItemRQ - object with item parameters.
|
|
481
|
+
* finishTestItemRQ should look like this
|
|
482
|
+
{
|
|
483
|
+
"endTime": this.helper.now(),
|
|
484
|
+
"issue": {
|
|
485
|
+
"comment": "string",
|
|
486
|
+
"externalSystemIssues": [
|
|
487
|
+
{
|
|
488
|
+
"submitDate": 0,
|
|
489
|
+
"submitter": "string",
|
|
490
|
+
"systemId": "string",
|
|
491
|
+
"ticketId": "string",
|
|
492
|
+
"url": "string"
|
|
493
|
+
}
|
|
494
|
+
],
|
|
495
|
+
"issueType": "string"
|
|
496
|
+
},
|
|
497
|
+
"status": "passed" or one of 'passed', 'failed', 'stopped', 'skipped', 'interrupted', 'cancelled'
|
|
498
|
+
}
|
|
499
|
+
* @Returns {Object} - an object which contains a tempId and a promise
|
|
500
|
+
*/
|
|
501
|
+
finishTestItem(itemTempId, finishTestItemRQ) {
|
|
502
|
+
const itemObj = this.map[itemTempId];
|
|
503
|
+
if (!itemObj) {
|
|
504
|
+
return this.getRejectAnswer(itemTempId, new Error(`Item "${itemTempId}" not found`));
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const finishTestItemData = {
|
|
508
|
+
endTime: this.helpers.now(),
|
|
509
|
+
...(itemObj.children.length ? {} : { status: RP_STATUSES.PASSED }),
|
|
510
|
+
...finishTestItemRQ,
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
itemObj.finishSend = true;
|
|
514
|
+
Promise.all(itemObj.children.map((itemId) => this.map[itemId] && this.map[itemId].promiseFinish))
|
|
515
|
+
.then(() => {
|
|
516
|
+
this.cleanMap(itemObj.children);
|
|
517
|
+
this.finishTestItemPromiseStart(
|
|
518
|
+
itemObj,
|
|
519
|
+
itemTempId,
|
|
520
|
+
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
|
|
521
|
+
);
|
|
522
|
+
}, () => {
|
|
523
|
+
this.cleanMap(itemObj.children);
|
|
524
|
+
this.logDebug(`Error finish children of test item ${itemTempId}`);
|
|
525
|
+
this.logDebug(`Finish test item ${itemTempId}`);
|
|
526
|
+
this.finishTestItemPromiseStart(
|
|
527
|
+
itemObj,
|
|
528
|
+
itemTempId,
|
|
529
|
+
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
|
|
530
|
+
);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
return {
|
|
534
|
+
tempId: itemTempId,
|
|
535
|
+
promise: itemObj.promiseFinish,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
saveLog(itemObj, requestPromiseFunc) {
|
|
540
|
+
const tempId = this.getUniqId();
|
|
541
|
+
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
|
|
542
|
+
itemObj.promiseStart.then(() => {
|
|
543
|
+
this.logDebug(`Save log ${tempId}`);
|
|
544
|
+
requestPromiseFunc(itemObj.realId, this.launchUuid).then((response) => {
|
|
545
|
+
this.logDebug(`Successfully save log ${tempId}`);
|
|
546
|
+
resolve(response);
|
|
547
|
+
}, (error) => {
|
|
548
|
+
this.logDebug(`Error finish log: ${error}`);
|
|
549
|
+
reject(error);
|
|
550
|
+
});
|
|
551
|
+
}, (error) => {
|
|
552
|
+
reject(error);
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
itemObj.children.push(tempId);
|
|
556
|
+
|
|
557
|
+
const logObj = this.map[tempId];
|
|
558
|
+
logObj.finishSend = true;
|
|
559
|
+
logObj.promiseStart.then((response) => logObj.resolveFinish(response), (error) => logObj.rejectFinish(error));
|
|
560
|
+
|
|
561
|
+
return {
|
|
562
|
+
tempId,
|
|
563
|
+
promise: this.map[tempId].promiseFinish,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
sendLog(itemTempId, saveLogRQ, fileObj) {
|
|
568
|
+
const saveLogData = {
|
|
569
|
+
time: this.helpers.now(),
|
|
570
|
+
message: '',
|
|
571
|
+
level: '',
|
|
572
|
+
...saveLogRQ,
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
if (fileObj) {
|
|
576
|
+
return this.sendLogWithFile(itemTempId, saveLogData, fileObj);
|
|
577
|
+
}
|
|
578
|
+
return this.sendLogWithoutFile(itemTempId, saveLogData);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Send log of test results.
|
|
583
|
+
* @param {string} itemTempId - temp item id (returned in the query "startTestItem").
|
|
584
|
+
* @param {Object} saveLogRQ - object with data of test result.
|
|
585
|
+
* saveLogRQ should look like this
|
|
586
|
+
* {
|
|
587
|
+
* level: 'error' or one of 'trace', 'debug', 'info', 'warn', 'error', '',
|
|
588
|
+
* message: 'string' (support markdown),
|
|
589
|
+
* time: this.helpers.now()
|
|
590
|
+
* }
|
|
591
|
+
* @Returns {Object} - an object which contains a tempId and a promise
|
|
592
|
+
*/
|
|
593
|
+
sendLogWithoutFile(itemTempId, saveLogRQ) {
|
|
594
|
+
const itemObj = this.map[itemTempId];
|
|
595
|
+
if (!itemObj) {
|
|
596
|
+
return this.getRejectAnswer(itemTempId, new Error(`Item "${itemTempId}" not found`));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const requestPromise = (itemUuid, launchUuid) => {
|
|
600
|
+
const url = 'log';
|
|
601
|
+
const isItemUuid = itemUuid !== launchUuid;
|
|
602
|
+
return this.restClient.create(
|
|
603
|
+
url,
|
|
604
|
+
Object.assign(
|
|
605
|
+
saveLogRQ,
|
|
606
|
+
{ launchUuid },
|
|
607
|
+
isItemUuid && { itemUuid },
|
|
608
|
+
),
|
|
609
|
+
{ headers: this.headers },
|
|
610
|
+
);
|
|
611
|
+
};
|
|
612
|
+
return this.saveLog(itemObj, requestPromise);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Send log of test results with file.
|
|
617
|
+
* @param {string} itemTempId - temp item id (returned in the query "startTestItem").
|
|
618
|
+
* @param {Object} saveLogRQ - object with data of test result.
|
|
619
|
+
* saveLogRQ should look like this
|
|
620
|
+
* {
|
|
621
|
+
* level: 'error' or one of 'trace', 'debug', 'info', 'warn', 'error', '',
|
|
622
|
+
* message: 'string' (support markdown),
|
|
623
|
+
* time: this.helpers.now()
|
|
624
|
+
* }
|
|
625
|
+
* @param {Object} fileObj - object with file data.
|
|
626
|
+
* fileObj should look like this
|
|
627
|
+
* {
|
|
628
|
+
name: 'string',
|
|
629
|
+
type: "image/png" or your file mimeType
|
|
630
|
+
(supported types: 'image/*', application/ ['xml', 'javascript', 'json', 'css', 'php'],
|
|
631
|
+
another format will be opened in a new browser tab ),
|
|
632
|
+
content: file
|
|
633
|
+
* }
|
|
634
|
+
* @Returns {Object} - an object which contains a tempId and a promise
|
|
635
|
+
*/
|
|
636
|
+
sendLogWithFile(itemTempId, saveLogRQ, fileObj) {
|
|
637
|
+
const itemObj = this.map[itemTempId];
|
|
638
|
+
if (!itemObj) {
|
|
639
|
+
return this.getRejectAnswer(itemTempId, new Error(`Item "${itemTempId}" not found`));
|
|
640
|
+
}
|
|
641
|
+
// eslint-disable-next-line max-len
|
|
642
|
+
const requestPromise = (itemUuid, launchUuid) => {
|
|
643
|
+
const isItemUuid = itemUuid !== launchUuid;
|
|
644
|
+
|
|
645
|
+
// eslint-disable-next-line max-len
|
|
646
|
+
return this.getRequestLogWithFile(Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }), fileObj);
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
return this.saveLog(itemObj, requestPromise);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
getRequestLogWithFile(saveLogRQ, fileObj) {
|
|
653
|
+
const url = 'log';
|
|
654
|
+
// eslint-disable-next-line no-param-reassign
|
|
655
|
+
saveLogRQ.file = { name: fileObj.name };
|
|
656
|
+
return this.restClient.create(
|
|
657
|
+
url,
|
|
658
|
+
this.buildMultiPartStream([saveLogRQ], fileObj, MULTIPART_BOUNDARY),
|
|
659
|
+
{
|
|
660
|
+
headers: { ...this.headers, 'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}` },
|
|
661
|
+
},
|
|
662
|
+
)
|
|
663
|
+
.then((response) => response)
|
|
664
|
+
.catch((error) => {
|
|
665
|
+
this.logDebug('ERROR');
|
|
666
|
+
this.logDebug(error);
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// eslint-disable-next-line valid-jsdoc
|
|
671
|
+
/**
|
|
672
|
+
*
|
|
673
|
+
* @Private
|
|
674
|
+
*/
|
|
675
|
+
buildMultiPartStream(jsonPart, filePart, boundary) {
|
|
676
|
+
const eol = "\r\n";
|
|
677
|
+
const bx = `--${boundary}`;
|
|
678
|
+
const buffers = [
|
|
679
|
+
// eslint-disable-next-line function-paren-newline
|
|
680
|
+
Buffer.from(
|
|
681
|
+
// eslint-disable-next-line prefer-template
|
|
682
|
+
bx + eol + "Content-Disposition: form-data; name=\"json_request_part\""
|
|
683
|
+
+ eol + "Content-Type: application/json" + eol
|
|
684
|
+
+ eol + eol + JSON.stringify(jsonPart) + eol,
|
|
685
|
+
),
|
|
686
|
+
// eslint-disable-next-line function-paren-newline
|
|
687
|
+
Buffer.from(
|
|
688
|
+
// eslint-disable-next-line prefer-template
|
|
689
|
+
bx + eol + "Content-Disposition: form-data; name=\"file\"; filename=\"" + filePart.name + "\"" + eol
|
|
690
|
+
+ "Content-Type: " + filePart.type + eol + eol,
|
|
691
|
+
),
|
|
692
|
+
Buffer.from(filePart.content, 'base64'),
|
|
693
|
+
Buffer.from(`${eol + bx}--${eol}`),
|
|
694
|
+
];
|
|
695
|
+
return Buffer.concat(buffers);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
finishTestItemPromiseStart(itemObj, itemTempId, finishTestItemData) {
|
|
699
|
+
itemObj.promiseStart
|
|
700
|
+
.then(() => {
|
|
701
|
+
const url = ['item', itemObj.realId].join('/');
|
|
702
|
+
this.logDebug(`Finish test item ${itemTempId}`);
|
|
703
|
+
// eslint-disable-next-line max-len
|
|
704
|
+
this.restClient.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid }), { headers: this.headers })
|
|
705
|
+
.then((response) => {
|
|
706
|
+
this.logDebug(`Success finish item ${itemTempId}`);
|
|
707
|
+
itemObj.resolveFinish(response);
|
|
708
|
+
}, (error) => {
|
|
709
|
+
this.logDebug(`Error finish test item ${itemTempId}`);
|
|
710
|
+
console.dir(error);
|
|
711
|
+
itemObj.rejectFinish(error);
|
|
712
|
+
});
|
|
713
|
+
}, (error) => {
|
|
714
|
+
itemObj.rejectFinish(error);
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
module.exports = RPClient;
|