@@ -223,16 +223,16 @@ class Log {
223
223
cy : any
224
224
state : any
225
225
config : any
226
- logManager : LogManager
226
+ fireChangeEvent : ( ( log ) => ( void | undefined ) )
227
227
obj : any
228
228
229
229
private attributes : Record < string , any > = { }
230
230
231
- constructor ( cy , state , config , logManager , obj ) {
231
+ constructor ( cy , state , config , fireChangeEvent , obj ) {
232
232
this . cy = cy
233
233
this . state = state
234
234
this . config = config
235
- this . logManager = logManager
235
+ this . fireChangeEvent = fireChangeEvent
236
236
this . obj = defaults ( state , config , obj )
237
237
238
238
extendEvents ( this )
@@ -321,7 +321,7 @@ class Log {
321
321
this . setElAttrs ( )
322
322
}
323
323
324
- this . logManager . fireChangeEvent ( this )
324
+ this . fireChangeEvent ( this )
325
325
326
326
return this
327
327
}
@@ -513,6 +513,10 @@ class Log {
513
513
class LogManager {
514
514
logs : Record < string , any > = { }
515
515
516
+ constructor ( ) {
517
+ this . fireChangeEvent = this . fireChangeEvent . bind ( this )
518
+ }
519
+
516
520
trigger ( log , event ) {
517
521
// bail if we never fired our initial log event
518
522
if ( ! log . _hasInitiallyLogged ) {
@@ -560,76 +564,78 @@ class LogManager {
560
564
561
565
return debounceFn ( )
562
566
}
563
- }
564
567
565
- export function create ( Cypress , cy , state , config ) {
566
- counter = 0
567
- const logManager = new LogManager ( )
568
-
569
- const logFn = function ( options : any = { } ) {
570
- if ( ! _ . isObject ( options ) ) {
571
- $errUtils . throwErrByPath ( 'log.invalid_argument' , { args : { arg : options } } )
572
- }
568
+ createLogFn ( cy , state , config ) {
569
+ return ( options : any = { } ) => {
570
+ if ( ! _ . isObject ( options ) ) {
571
+ $errUtils . throwErrByPath ( 'log.invalid_argument' , { args : { arg : options } } )
572
+ }
573
573
574
- const log = new Log ( cy , state , config , logManager , options )
574
+ const log = new Log ( cy , state , config , this . fireChangeEvent , options )
575
575
576
- log . set ( options )
576
+ log . set ( options )
577
577
578
- // if snapshot was passed
579
- // in, go ahead and snapshot
580
- if ( log . get ( 'snapshot' ) ) {
581
- log . snapshot ( )
582
- }
578
+ // if snapshot was passed
579
+ // in, go ahead and snapshot
580
+ if ( log . get ( 'snapshot' ) ) {
581
+ log . snapshot ( )
582
+ }
583
583
584
- // if end was passed in
585
- // go ahead and end
586
- if ( log . get ( 'end' ) ) {
587
- log . end ( )
588
- }
584
+ // if end was passed in
585
+ // go ahead and end
586
+ if ( log . get ( 'end' ) ) {
587
+ log . end ( )
588
+ }
589
589
590
- if ( log . get ( 'error' ) ) {
591
- log . error ( log . get ( 'error' ) )
592
- }
590
+ if ( log . get ( 'error' ) ) {
591
+ log . error ( log . get ( 'error' ) )
592
+ }
593
593
594
- log . wrapConsoleProps ( )
594
+ log . wrapConsoleProps ( )
595
595
596
- const onBeforeLog = state ( 'onBeforeLog' )
596
+ const onBeforeLog = state ( 'onBeforeLog' )
597
597
598
- // dont trigger log if this function
599
- // explicitly returns false
600
- if ( _ . isFunction ( onBeforeLog ) ) {
601
- if ( onBeforeLog . call ( cy , log ) === false ) {
602
- return
598
+ // dont trigger log if this function
599
+ // explicitly returns false
600
+ if ( _ . isFunction ( onBeforeLog ) ) {
601
+ if ( onBeforeLog . call ( cy , log ) === false ) {
602
+ return
603
+ }
603
604
}
604
- }
605
605
606
- // set the log on the command
607
- const current = state ( 'current' )
606
+ // set the log on the command
607
+ const current = state ( 'current' )
608
608
609
- if ( current ) {
610
- current . log ( log )
611
- }
609
+ if ( current ) {
610
+ current . log ( log )
611
+ }
612
612
613
- logManager . addToLogs ( log )
613
+ this . addToLogs ( log )
614
614
615
- if ( options . sessionInfo ) {
616
- Cypress . emit ( 'session:add' , log . toJSON ( ) )
617
- }
615
+ if ( options . sessionInfo ) {
616
+ Cypress . emit ( 'session:add' , log . toJSON ( ) )
617
+ }
618
618
619
- if ( options . emitOnly ) {
620
- return
621
- }
619
+ if ( options . emitOnly ) {
620
+ return
621
+ }
622
622
623
- logManager . triggerLog ( log )
623
+ this . triggerLog ( log )
624
624
625
- // if not current state then the log is being run
626
- // with no command reference, so just end the log
627
- if ( ! current ) {
628
- log . end ( )
629
- }
625
+ // if not current state then the log is being run
626
+ // with no command reference, so just end the log
627
+ if ( ! current ) {
628
+ log . end ( )
629
+ }
630
630
631
- return log
631
+ return log
632
+ }
632
633
}
634
+ }
635
+
636
+ export function create ( Cypress , cy , state , config ) {
637
+ counter = 0
638
+ const logManager = new LogManager ( )
633
639
634
- return logFn
640
+ return logManager . createLogFn ( cy , state , config )
635
641
}
0 commit comments