@@ -80,7 +80,7 @@ describe("syncSpecsLogs", () => {
80
80
81
81
it ( 'should return proper request option for polling' , ( ) => {
82
82
let options = getOptions ( auth , build_id ) ;
83
- expect ( options . url ) . to . equal ( `${ config . buildUrl } ${ build_id } ` ) ;
83
+ expect ( options . url ) . to . equal ( `${ config . buildUrlV2 } ${ build_id } ` ) ;
84
84
expect ( options . auth . user ) . to . equal ( auth . username ) ;
85
85
expect ( options . auth . password ) . to . equal ( auth . access_key ) ;
86
86
expect ( options . headers [ "Content-Type" ] ) . to . equal ( "application/json" ) ;
@@ -216,35 +216,38 @@ describe("syncSpecsLogs", () => {
216
216
217
217
context ( "showSpecsStatus" , ( ) => {
218
218
const showSpecsStatus = syncSpecsLogs . __get__ ( "showSpecsStatus" ) ;
219
+ const buildCreatedStatusCode = 202
220
+ const buildRunningStatusCode = 204
221
+ const buildCompletedStatusCode = 200
219
222
220
223
it ( 'should not print initial log for running specs when it is the 1st polling response' , ( ) => {
221
- let data = JSON . stringify ( [ "created" ] )
224
+ let data = JSON . stringify ( { "specData" : [ "created" ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
222
225
var printInitialLog = sandbox . stub ( ) ;
223
226
syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
224
227
225
- showSpecsStatus ( data ) ;
228
+ showSpecsStatus ( data , buildCreatedStatusCode ) ;
226
229
227
230
expect ( printInitialLog . calledOnce ) . to . be . false ;
228
231
} ) ;
229
232
230
233
it ( 'should print spec details when spec related data is sent in polling response' , ( ) => {
231
234
let specResult = JSON . stringify ( { "path" : "path" } )
232
- let data = JSON . stringify ( [ specResult ] )
235
+ let data = JSON . stringify ( { "specData" : [ specResult ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
233
236
var printSpecData = sandbox . stub ( ) ;
234
237
syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
235
- showSpecsStatus ( data ) ;
238
+ showSpecsStatus ( data , buildRunningStatusCode ) ;
236
239
expect ( printSpecData . calledOnce ) . to . be . true ;
237
240
} ) ;
238
241
239
242
it ( 'should print initial and spec details when spec related data is sent in polling response' , ( ) => {
240
243
let specResult = JSON . stringify ( { "path" : "path" } )
241
244
syncSpecsLogs . __set__ ( 'buildStarted' , false )
242
- let data = JSON . stringify ( [ "created" , specResult ] )
245
+ let data = JSON . stringify ( { "specData" : [ specResult ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
243
246
var printSpecData = sandbox . stub ( ) ;
244
247
syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
245
248
var printInitialLog = sandbox . stub ( ) ;
246
249
syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
247
- showSpecsStatus ( data ) ;
250
+ showSpecsStatus ( data , buildCreatedStatusCode ) ;
248
251
expect ( printSpecData . calledOnce ) . to . be . true ;
249
252
expect ( printInitialLog . calledOnce ) . to . be . true ;
250
253
} ) ;
@@ -253,18 +256,38 @@ describe("syncSpecsLogs", () => {
253
256
let specResult = JSON . stringify ( { "path" : "path" } )
254
257
let customError = { id : "custom_error_1" , type : "custom_errors_to_print" , level : "warn" , should_be_unique : true , message : "custom error message" }
255
258
syncSpecsLogs . __set__ ( 'buildStarted' , false )
256
- let data = JSON . stringify ( [ "created" , specResult , customError ] )
259
+ let data = JSON . stringify ( { "specData" : [ "created" , specResult , customError ] , "buildData" : { "duration" : "NA" , "parallels" : "NA" } } )
257
260
var printSpecData = sandbox . stub ( ) ;
258
261
syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
259
262
var printInitialLog = sandbox . stub ( ) ;
260
263
syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
261
264
var addCustomErrorToPrint = sandbox . stub ( ) ;
262
265
syncSpecsLogs . __set__ ( 'addCustomErrorToPrint' , addCustomErrorToPrint ) ;
263
- showSpecsStatus ( data ) ;
266
+ showSpecsStatus ( data , buildRunningStatusCode ) ;
264
267
expect ( printSpecData . calledOnce ) . to . be . true ;
265
268
expect ( printInitialLog . calledOnce ) . to . be . true ;
266
269
expect ( addCustomErrorToPrint . calledOnce ) . to . be . true ;
267
270
} ) ;
271
+
272
+ it ( 'should add custom error, print initial and spec details when spec related data and duration is sent in polling response' , ( ) => {
273
+ let specResult = JSON . stringify ( { "path" : "path" } )
274
+ let customError = { id : "custom_error_1" , type : "custom_errors_to_print" , level : "warn" , should_be_unique : true , message : "custom error message" }
275
+ var loggerInfoSpy = sinon . spy ( logger , 'info' ) ;
276
+ syncSpecsLogs . __set__ ( 'buildStarted' , false )
277
+ let data = JSON . stringify ( { "specData" : [ "created" , specResult , customError ] , "buildData" : { "duration" : { "total_duration" : "87" } , "parallels" : "2" } } )
278
+ var printSpecData = sandbox . stub ( ) ;
279
+ syncSpecsLogs . __set__ ( 'printSpecData' , printSpecData ) ;
280
+ var printInitialLog = sandbox . stub ( ) ;
281
+ syncSpecsLogs . __set__ ( 'printInitialLog' , printInitialLog ) ;
282
+ var addCustomErrorToPrint = sandbox . stub ( ) ;
283
+ syncSpecsLogs . __set__ ( 'addCustomErrorToPrint' , addCustomErrorToPrint ) ;
284
+ showSpecsStatus ( data , buildCompletedStatusCode ) ;
285
+ expect ( printSpecData . calledOnce ) . to . be . true ;
286
+ expect ( printInitialLog . calledOnce ) . to . be . true ;
287
+ expect ( addCustomErrorToPrint . calledOnce ) . to . be . true ;
288
+ sinon . assert . calledWith ( loggerInfoSpy , 'Done in 87 seconds with 2 parallels.\n' ) ;
289
+ loggerInfoSpy . restore ( ) ;
290
+ } ) ;
268
291
} ) ;
269
292
270
293
context ( "printSpecsStatus" , ( ) => {
0 commit comments