@@ -16,6 +16,8 @@ let fakeConsole;
16
16
let legacyRender ;
17
17
let mockError ;
18
18
let mockInfo ;
19
+ let mockGroup ;
20
+ let mockGroupCollapsed ;
19
21
let mockLog ;
20
22
let mockWarn ;
21
23
let patchConsole ;
@@ -25,6 +27,7 @@ let rendererID;
25
27
describe ( 'console' , ( ) => {
26
28
beforeEach ( ( ) => {
27
29
const Console = require ( 'react-devtools-shared/src/backend/console' ) ;
30
+
28
31
patchConsole = Console . patch ;
29
32
unpatchConsole = Console . unpatch ;
30
33
@@ -33,13 +36,17 @@ describe('console', () => {
33
36
// because Jest itself has hooks into it as does our test env setup.
34
37
mockError = jest . fn ( ) ;
35
38
mockInfo = jest . fn ( ) ;
39
+ mockGroup = jest . fn ( ) ;
40
+ mockGroupCollapsed = jest . fn ( ) ;
36
41
mockLog = jest . fn ( ) ;
37
42
mockWarn = jest . fn ( ) ;
38
43
fakeConsole = {
39
44
error : mockError ,
40
45
info : mockInfo ,
41
46
log : mockLog ,
42
47
warn : mockWarn ,
48
+ group : mockGroup ,
49
+ groupCollapsed : mockGroupCollapsed ,
43
50
} ;
44
51
45
52
Console . dangerous_setTargetConsoleForTesting ( fakeConsole ) ;
@@ -69,6 +76,8 @@ describe('console', () => {
69
76
expect ( fakeConsole . info ) . toBe ( mockInfo ) ;
70
77
expect ( fakeConsole . log ) . toBe ( mockLog ) ;
71
78
expect ( fakeConsole . warn ) . not . toBe ( mockWarn ) ;
79
+ expect ( fakeConsole . group ) . toBe ( mockGroup ) ;
80
+ expect ( fakeConsole . groupCollapsed ) . toBe ( mockGroupCollapsed ) ;
72
81
} ) ;
73
82
74
83
// @reactVersion >=18.0
@@ -491,6 +500,9 @@ describe('console', () => {
491
500
fakeConsole . log ( 'log' ) ;
492
501
fakeConsole . warn ( 'warn' ) ;
493
502
fakeConsole . error ( 'error' ) ;
503
+ fakeConsole . info ( 'info' ) ;
504
+ fakeConsole . group ( 'group' ) ;
505
+ fakeConsole . groupCollapsed ( 'groupCollapsed' ) ;
494
506
return < div /> ;
495
507
}
496
508
@@ -528,6 +540,36 @@ describe('console', () => {
528
540
`color: ${ process . env . DARK_MODE_DIMMED_ERROR_COLOR } ` ,
529
541
'error' ,
530
542
] ) ;
543
+
544
+ expect ( mockInfo ) . toHaveBeenCalledTimes ( 2 ) ;
545
+ expect ( mockInfo . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
546
+ expect ( mockInfo . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'info' ) ;
547
+ expect ( mockInfo . mock . calls [ 1 ] ) . toHaveLength ( 3 ) ;
548
+ expect ( mockInfo . mock . calls [ 1 ] ) . toEqual ( [
549
+ '%c%s' ,
550
+ `color: ${ process . env . DARK_MODE_DIMMED_LOG_COLOR } ` ,
551
+ 'info' ,
552
+ ] ) ;
553
+
554
+ expect ( mockGroup ) . toHaveBeenCalledTimes ( 2 ) ;
555
+ expect ( mockGroup . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
556
+ expect ( mockGroup . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'group' ) ;
557
+ expect ( mockGroup . mock . calls [ 1 ] ) . toHaveLength ( 3 ) ;
558
+ expect ( mockGroup . mock . calls [ 1 ] ) . toEqual ( [
559
+ '%c%s' ,
560
+ `color: ${ process . env . DARK_MODE_DIMMED_LOG_COLOR } ` ,
561
+ 'group' ,
562
+ ] ) ;
563
+
564
+ expect ( mockGroupCollapsed ) . toHaveBeenCalledTimes ( 2 ) ;
565
+ expect ( mockGroupCollapsed . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
566
+ expect ( mockGroupCollapsed . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'groupCollapsed' ) ;
567
+ expect ( mockGroupCollapsed . mock . calls [ 1 ] ) . toHaveLength ( 3 ) ;
568
+ expect ( mockGroupCollapsed . mock . calls [ 1 ] ) . toEqual ( [
569
+ '%c%s' ,
570
+ `color: ${ process . env . DARK_MODE_DIMMED_LOG_COLOR } ` ,
571
+ 'groupCollapsed' ,
572
+ ] ) ;
531
573
} ) ;
532
574
533
575
it ( 'should not double log if hideConsoleLogsInStrictMode is enabled in Strict mode' , ( ) => {
@@ -538,9 +580,16 @@ describe('console', () => {
538
580
const root = ReactDOMClient . createRoot ( container ) ;
539
581
540
582
function App ( ) {
583
+ console . log (
584
+ 'CALL' ,
585
+ global . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ ,
586
+ ) ;
541
587
fakeConsole . log ( 'log' ) ;
542
588
fakeConsole . warn ( 'warn' ) ;
543
589
fakeConsole . error ( 'error' ) ;
590
+ fakeConsole . info ( 'info' ) ;
591
+ fakeConsole . group ( 'group' ) ;
592
+ fakeConsole . groupCollapsed ( 'groupCollapsed' ) ;
544
593
return < div /> ;
545
594
}
546
595
@@ -563,6 +612,18 @@ describe('console', () => {
563
612
expect ( mockError ) . toHaveBeenCalledTimes ( 1 ) ;
564
613
expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
565
614
expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'error' ) ;
615
+
616
+ expect ( mockInfo ) . toHaveBeenCalledTimes ( 1 ) ;
617
+ expect ( mockInfo . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
618
+ expect ( mockInfo . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'info' ) ;
619
+
620
+ expect ( mockGroup ) . toHaveBeenCalledTimes ( 1 ) ;
621
+ expect ( mockGroup . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
622
+ expect ( mockGroup . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'group' ) ;
623
+
624
+ expect ( mockGroupCollapsed ) . toHaveBeenCalledTimes ( 1 ) ;
625
+ expect ( mockGroupCollapsed . mock . calls [ 0 ] ) . toHaveLength ( 1 ) ;
626
+ expect ( mockGroupCollapsed . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'groupCollapsed' ) ;
566
627
} ) ;
567
628
568
629
it ( 'should double log in Strict mode initial render for extension' , ( ) => {
@@ -734,13 +795,17 @@ describe('console error', () => {
734
795
// because Jest itself has hooks into it as does our test env setup.
735
796
mockError = jest . fn ( ) ;
736
797
mockInfo = jest . fn ( ) ;
798
+ mockGroup = jest . fn ( ) ;
799
+ mockGroupCollapsed = jest . fn ( ) ;
737
800
mockLog = jest . fn ( ) ;
738
801
mockWarn = jest . fn ( ) ;
739
802
fakeConsole = {
740
803
error : mockError ,
741
804
info : mockInfo ,
742
805
log : mockLog ,
743
806
warn : mockWarn ,
807
+ group : mockGroup ,
808
+ groupCollapsed : mockGroupCollapsed ,
744
809
} ;
745
810
746
811
Console . dangerous_setTargetConsoleForTesting ( fakeConsole ) ;
0 commit comments