17
17
/* eslint-disable no-undef */
18
18
const path = require ( 'path' ) ;
19
19
const { getOptions, RPClient } = require ( './mocks/reportportal-client.mock' ) ;
20
- const JestReportPortal = require ( '../index' ) ;
20
+ const JestReportPortal = require ( '../src' ) ;
21
+ const { TEST_ITEM_STATUSES , LOG_LEVEL } = require ( '../src/constants' ) ;
21
22
const pjson = require ( '../package.json' ) ;
23
+ const {
24
+ duration,
25
+ skippedTestResult,
26
+ testResult,
27
+ testObj,
28
+ mockDate,
29
+ mockFile,
30
+ } = require ( './mocks/data' ) ;
22
31
23
- const testItemStatuses = { PASSED : 'passed' , FAILED : 'failed' , SKIPPED : 'pending' } ;
24
32
const GLOBAL_CONFIG = { } ;
25
33
const options = getOptions ( ) ;
26
34
const currentDate = new Date ( ) ;
@@ -30,22 +38,6 @@ const systemAttr = {
30
38
value : `${ pjson . name } |${ pjson . version } ` ,
31
39
system : true ,
32
40
} ;
33
- const duration = 5 ;
34
- const testResult = {
35
- testResults : [
36
- {
37
- title : 'Title' ,
38
- status : 'failed' ,
39
- ancestorTitles : [ 'Suite name' , 'Test name' ] ,
40
- failureMessages : 'error message' ,
41
- invocations : 1 ,
42
- duration,
43
- } ,
44
- ] ,
45
- } ;
46
- const testObj = {
47
- path : `C:${ path . sep } testProject${ path . sep } example.js` ,
48
- } ;
49
41
50
42
describe ( 'index script' , ( ) => {
51
43
let reporter ;
@@ -118,17 +110,13 @@ describe('index script', () => {
118
110
reporter . onTestResult ( testObj , testResult ) ;
119
111
120
112
expect ( spyStartSuite ) . toHaveBeenCalledWith (
121
- testResult . testResults [ 0 ] . ancestorTitles [ 0 ] ,
122
- testObj . path ,
123
- duration ,
124
- ) ;
125
- expect ( spyStartTest ) . toHaveBeenCalledWith (
126
- testResult . testResults [ 0 ] ,
113
+ skippedTestResult . ancestorTitles [ 0 ] ,
127
114
testObj . path ,
128
115
duration ,
129
116
) ;
130
- expect ( spyStartStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , false , testObj . path ) ;
131
- expect ( spyFinishStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , false ) ;
117
+ expect ( spyStartTest ) . toHaveBeenCalledWith ( skippedTestResult , testObj . path , duration ) ;
118
+ expect ( spyStartStep ) . toHaveBeenCalledWith ( skippedTestResult , false , testObj . path ) ;
119
+ expect ( spyFinishStep ) . toHaveBeenCalledWith ( skippedTestResult ) ;
132
120
expect ( spyFinishTest ) . toHaveBeenCalledWith ( '1234' , 'tempTestId' ) ;
133
121
expect ( spyFinishSuite ) . toHaveBeenCalledWith ( '4321' , 'tempSuiteId' ) ;
134
122
} ,
@@ -143,8 +131,8 @@ describe('index script', () => {
143
131
144
132
reporter . onTestResult ( testObj , testResult ) ;
145
133
146
- expect ( spyStartStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , false , testObj . path ) ;
147
- expect ( spyFinishStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , false ) ;
134
+ expect ( spyStartStep ) . toHaveBeenCalledWith ( skippedTestResult , false , testObj . path ) ;
135
+ expect ( spyFinishStep ) . toHaveBeenCalledWith ( skippedTestResult ) ;
148
136
expect ( spyStartStep ) . toHaveBeenCalledTimes ( 1 ) ;
149
137
expect ( spyFinishStep ) . toHaveBeenCalledTimes ( 1 ) ;
150
138
} ,
@@ -156,13 +144,14 @@ describe('index script', () => {
156
144
( ) => {
157
145
const spyStartStep = jest . spyOn ( reporter , '_startStep' ) ;
158
146
const spyFinishStep = jest . spyOn ( reporter , '_finishStep' ) ;
147
+
159
148
const testResult = {
160
149
testResults : [
161
150
{
162
151
title : 'Title' ,
163
- status : 'failed' ,
152
+ status : TEST_ITEM_STATUSES . SKIPPED ,
164
153
ancestorTitles : [ 'Suite name' , 'Test name' ] ,
165
- failureMessages : 'error message' ,
154
+ failureMessages : [ ] ,
166
155
invocations : 2 ,
167
156
} ,
168
157
] ,
@@ -171,7 +160,7 @@ describe('index script', () => {
171
160
reporter . onTestResult ( testObj , testResult ) ;
172
161
173
162
expect ( spyStartStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , true , testObj . path ) ;
174
- expect ( spyFinishStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , true ) ;
163
+ expect ( spyFinishStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] ) ;
175
164
expect ( spyStartStep ) . toHaveBeenCalledTimes ( 2 ) ;
176
165
expect ( spyFinishStep ) . toHaveBeenCalledTimes ( 2 ) ;
177
166
} ,
@@ -187,17 +176,17 @@ describe('index script', () => {
187
176
testResults : [
188
177
{
189
178
title : 'Title' ,
190
- status : 'failed' ,
179
+ status : TEST_ITEM_STATUSES . SKIPPED ,
191
180
ancestorTitles : [ 'Suite name' , 'Test name' ] ,
192
- failureMessages : 'error message' ,
181
+ failureMessages : [ ] ,
193
182
} ,
194
183
] ,
195
184
} ;
196
185
197
186
reporter . onTestResult ( testObj , testResult ) ;
198
187
199
188
expect ( spyStartStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , false , testObj . path ) ;
200
- expect ( spyFinishStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] , false ) ;
189
+ expect ( spyFinishStep ) . toHaveBeenCalledWith ( testResult . testResults [ 0 ] ) ;
201
190
} ,
202
191
) ;
203
192
@@ -358,19 +347,20 @@ describe('index script', () => {
358
347
} ) ;
359
348
} ) ;
360
349
361
- describe ( '_sendLog ' , ( ) => {
350
+ describe ( 'sendLog ' , ( ) => {
362
351
test ( 'sendLog should be called with parameters' , ( ) => {
363
- const expectedLogObjectParameter = {
364
- message : 'message' ,
365
- level : 'error' ,
366
- } ;
367
352
reporter . tempStepId = 'tempStepId' ;
368
353
369
- reporter . _sendLog ( 'message' ) ;
354
+ reporter . sendLog ( { message : 'message' , level : LOG_LEVEL . ERROR , file : mockFile } ) ;
370
355
371
356
expect ( reporter . client . sendLog ) . toHaveBeenCalledWith (
372
357
'tempStepId' ,
373
- expectedLogObjectParameter ,
358
+ {
359
+ message : 'message' ,
360
+ level : LOG_LEVEL . ERROR ,
361
+ time : mockDate ,
362
+ } ,
363
+ mockFile ,
374
364
) ;
375
365
} ) ;
376
366
} ) ;
@@ -381,7 +371,7 @@ describe('index script', () => {
381
371
const spyFinishFailedTest = jest . spyOn ( reporter , '_finishFailedStep' ) ;
382
372
const spyFinishSkippedTest = jest . spyOn ( reporter , '_finishSkippedStep' ) ;
383
373
384
- reporter . _finishStep ( { status : testItemStatuses . PASSED , failureMessages : [ ] } ) ;
374
+ reporter . _finishStep ( { status : TEST_ITEM_STATUSES . PASSED , failureMessages : [ ] } ) ;
385
375
386
376
expect ( spyFinishPassedTest ) . toHaveBeenCalled ( ) ;
387
377
expect ( spyFinishFailedTest ) . not . toHaveBeenCalled ( ) ;
@@ -394,11 +384,11 @@ describe('index script', () => {
394
384
const spyFinishSkippedTest = jest . spyOn ( reporter , '_finishSkippedStep' ) ;
395
385
396
386
reporter . _finishStep (
397
- { status : testItemStatuses . FAILED , failureMessages : [ 'error message' ] } ,
387
+ { status : TEST_ITEM_STATUSES . FAILED , failureMessages : [ 'error message' ] } ,
398
388
false ,
399
389
) ;
400
390
401
- expect ( spyFinishFailedTest ) . toHaveBeenCalledWith ( 'error message' , false ) ;
391
+ expect ( spyFinishFailedTest ) . toHaveBeenCalledWith ( 'error message' ) ;
402
392
expect ( spyFinishPassedTest ) . not . toHaveBeenCalled ( ) ;
403
393
expect ( spyFinishSkippedTest ) . not . toHaveBeenCalled ( ) ;
404
394
} ) ;
@@ -408,7 +398,7 @@ describe('index script', () => {
408
398
const spyFinishFailedTest = jest . spyOn ( reporter , '_finishFailedStep' ) ;
409
399
const spyFinishSkippedTest = jest . spyOn ( reporter , '_finishSkippedStep' ) ;
410
400
411
- reporter . _finishStep ( { status : testItemStatuses . SKIPPED , failureMessages : [ ] } ) ;
401
+ reporter . _finishStep ( { status : TEST_ITEM_STATUSES . SKIPPED , failureMessages : [ ] } ) ;
412
402
413
403
expect ( spyFinishSkippedTest ) . toHaveBeenCalled ( ) ;
414
404
expect ( spyFinishPassedTest ) . not . toHaveBeenCalled ( ) ;
@@ -454,7 +444,6 @@ describe('index script', () => {
454
444
test ( 'finishTestItem should be called with parameters' , ( ) => {
455
445
const expectedFinishTestItemParameter = {
456
446
status : 'passed' ,
457
- retry : false ,
458
447
} ;
459
448
reporter . tempStepId = 'tempStepId' ;
460
449
@@ -468,29 +457,49 @@ describe('index script', () => {
468
457
} ) ;
469
458
470
459
describe ( '_finishFailedStep' , ( ) => {
471
- test ( '_sendLog should be called with failure message, finishTestItem should be called with parameters' , ( ) => {
472
- const spySendLog = jest . spyOn ( reporter , '_sendLog' ) ;
460
+ test ( 'sendLog should be called with failure message, finishTestItem should be called with parameters' , ( ) => {
461
+ const spySendLog = jest . spyOn ( reporter , 'sendLog' ) ;
462
+ const errorMessage = 'error message' ;
463
+ const tempStepId = 'tempStepId' ;
473
464
const expectedFinishTestItemParameter = {
474
465
status : 'failed' ,
475
- retry : false ,
466
+ description : '```error\nerror message\n```' ,
476
467
} ;
477
- reporter . tempStepId = ' tempStepId' ;
468
+ reporter . tempStepId = tempStepId ;
478
469
479
- reporter . _finishFailedStep ( 'error message' , false ) ;
470
+ reporter . _finishFailedStep ( errorMessage , false ) ;
480
471
481
- expect ( spySendLog ) . toHaveBeenCalledWith ( 'error message' ) ;
472
+ expect ( spySendLog ) . toHaveBeenCalledWith ( { message : errorMessage , level : LOG_LEVEL . ERROR } ) ;
482
473
expect ( reporter . client . finishTestItem ) . toHaveBeenCalledWith (
483
- ' tempStepId' ,
474
+ tempStepId ,
484
475
expectedFinishTestItemParameter ,
485
476
) ;
486
477
} ) ;
478
+
479
+ test (
480
+ 'finishTestItem should be called without description parameter ' +
481
+ 'if extendTestDescriptionWithLastError is false' ,
482
+ ( ) => {
483
+ const expectedFinishTestItemParameter = {
484
+ status : 'failed' ,
485
+ } ;
486
+ reporter . tempStepId = 'tempStepId' ;
487
+ reporter . reportOptions . extendTestDescriptionWithLastError = false ;
488
+
489
+ reporter . _finishFailedStep ( 'error message' , false ) ;
490
+
491
+ expect ( reporter . client . finishTestItem ) . toHaveBeenCalledWith (
492
+ 'tempStepId' ,
493
+ expectedFinishTestItemParameter ,
494
+ ) ;
495
+ } ,
496
+ ) ;
487
497
} ) ;
488
498
489
499
describe ( '_finishSkippedStep' , ( ) => {
490
500
test ( 'finishTestItem should be called with parameters' , ( ) => {
491
501
const expectedFinishTestItemParameter = {
492
502
status : 'skipped' ,
493
- retry : false ,
494
503
} ;
495
504
reporter . tempStepId = 'tempStepId' ;
496
505
@@ -505,7 +514,6 @@ describe('index script', () => {
505
514
test ( 'finishTestItem should be called with issue parameter if skippedIssue is false' , ( ) => {
506
515
const expectedFinishTestItemParameter = {
507
516
status : 'skipped' ,
508
- retry : false ,
509
517
issue : { issueType : 'NOT_ISSUE' } ,
510
518
} ;
511
519
reporter . tempStepId = 'tempStepId' ;
0 commit comments