@@ -21,7 +21,8 @@ const utils = require('../../../../bin/helpers/utils'),
21
21
fileHelpers = require ( '../../../../bin/helpers/fileHelpers' ) ,
22
22
testObjects = require ( '../../support/fixtures/testObjects' ) ,
23
23
syncLogger = require ( '../../../../bin/helpers/logger' ) . syncCliLogger ,
24
- Contants = require ( '../../../../bin/helpers/constants' ) ;
24
+ Contants = require ( '../../../../bin/helpers/constants' ) ,
25
+ o11yHelpers = require ( '../../../../bin/testObservability/helper/helper' ) ;
25
26
const browserstack = require ( 'browserstack-local' ) ;
26
27
const { CYPRESS_V10_AND_ABOVE_TYPE , CYPRESS_V9_AND_OLDER_TYPE } = require ( '../../../../bin/helpers/constants' ) ;
27
28
const { winstonLogger, syncCliLogger } = require ( '../../../../bin/helpers/logger' ) ;
@@ -3396,6 +3397,72 @@ describe('utils', () => {
3396
3397
} ) ;
3397
3398
} ) ;
3398
3399
3400
+ describe ( 'setO11yProcessHooks' , ( ) => {
3401
+ it ( 'should handle multiple calls' , ( done ) => {
3402
+ let buildId = null ;
3403
+ let bsConfig = testObjects . sampleBsConfig ;
3404
+ let bsLocalStub = sinon . stub ( ) ;
3405
+ let args = { } ;
3406
+
3407
+ let printBuildLinkStub = sinon . stub ( o11yHelpers , 'printBuildLink' ) . returns ( Promise . resolve ( true ) ) ;
3408
+ let processOnSpy = sinon . spy ( process , 'on' ) ;
3409
+
3410
+ utils . setO11yProcessHooks ( buildId , bsConfig , bsLocalStub , args ) ;
3411
+ sinon . assert . calledOnce ( processOnSpy ) ;
3412
+ processOnSpy . restore ( ) ;
3413
+ processOnSpy = sinon . spy ( process , 'on' ) ;
3414
+ utils . setO11yProcessHooks ( 'build_id' , bsConfig , bsLocalStub , args ) ;
3415
+ sinon . assert . notCalled ( processOnSpy ) ;
3416
+ processOnSpy . restore ( ) ;
3417
+ process . on ( 'beforeExit' , ( ) => {
3418
+ sinon . assert . calledOnce ( printBuildLinkStub ) ;
3419
+ sinon . assert . calledWith ( printBuildLinkStub , false ) ;
3420
+ done ( ) ;
3421
+ } ) ;
3422
+ process . emit ( 'beforeExit' ) ;
3423
+ printBuildLinkStub . restore ( ) ;
3424
+ sinon . stub . restore ( ) ;
3425
+ } ) ;
3426
+
3427
+ it ( 'should handle "beforeExit" event, with build id' , ( done ) => {
3428
+ let buildId = 'build_id' ;
3429
+ let bsConfig = testObjects . sampleBsConfig ;
3430
+ let bsLocalStub = sinon . stub ( ) ;
3431
+ let args = { } ;
3432
+
3433
+ let printBuildLinkStub = sinon . stub ( o11yHelpers , 'printBuildLink' ) . returns ( Promise . resolve ( true ) ) ;
3434
+
3435
+ utils . setO11yProcessHooks ( buildId , bsConfig , bsLocalStub , args ) ;
3436
+ process . on ( 'beforeExit' , ( ) => {
3437
+ sinon . assert . calledOnce ( printBuildLinkStub ) ;
3438
+ sinon . assert . calledWith ( printBuildLinkStub , false ) ;
3439
+ done ( ) ;
3440
+ } ) ;
3441
+ process . emit ( 'beforeExit' ) ;
3442
+ printBuildLinkStub . restore ( ) ;
3443
+ sinon . stub . restore ( ) ;
3444
+ } ) ;
3445
+
3446
+ it ( 'should handle "beforeExit" event, without build id' , ( done ) => {
3447
+ let buildId = null ;
3448
+ let bsConfig = testObjects . sampleBsConfig ;
3449
+ let bsLocalStub = sinon . stub ( ) ;
3450
+ let args = { } ;
3451
+
3452
+ let printBuildLinkStub = sinon . stub ( o11yHelpers , 'printBuildLink' ) . returns ( Promise . resolve ( true ) ) ;
3453
+
3454
+ utils . setO11yProcessHooks ( buildId , bsConfig , bsLocalStub , args ) ;
3455
+ process . on ( 'beforeExit' , ( ) => {
3456
+ sinon . assert . calledOnce ( printBuildLinkStub ) ;
3457
+ sinon . assert . calledWith ( printBuildLinkStub , true ) ;
3458
+ done ( ) ;
3459
+ } ) ;
3460
+ process . emit ( 'beforeExit' ) ;
3461
+ printBuildLinkStub . restore ( ) ;
3462
+ sinon . stub . restore ( ) ;
3463
+ } ) ;
3464
+ } ) ;
3465
+
3399
3466
describe ( 'fetchZipSize' , ( ) => {
3400
3467
it ( 'should return size in bytes if file is present' , ( ) => {
3401
3468
sinon . stub ( fs , 'statSync' ) . returns ( { size : 123 } ) ;
0 commit comments