@@ -21,7 +21,8 @@ const utils = require('../../../../bin/helpers/utils'),
2121 fileHelpers = require ( '../../../../bin/helpers/fileHelpers' ) ,
2222 testObjects = require ( '../../support/fixtures/testObjects' ) ,
2323 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' ) ;
2526const browserstack = require ( 'browserstack-local' ) ;
2627const { CYPRESS_V10_AND_ABOVE_TYPE , CYPRESS_V9_AND_OLDER_TYPE } = require ( '../../../../bin/helpers/constants' ) ;
2728const { winstonLogger, syncCliLogger } = require ( '../../../../bin/helpers/logger' ) ;
@@ -3396,6 +3397,72 @@ describe('utils', () => {
33963397 } ) ;
33973398 } ) ;
33983399
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+
33993466 describe ( 'fetchZipSize' , ( ) => {
34003467 it ( 'should return size in bytes if file is present' , ( ) => {
34013468 sinon . stub ( fs , 'statSync' ) . returns ( { size : 123 } ) ;
0 commit comments