@@ -59,4 +59,91 @@ describe('Unit | coreHandlers | handleScope', () => {
59
59
expect ( mockHandleScope ) . toHaveBeenCalledTimes ( 1 ) ;
60
60
expect ( mockHandleScope ) . toHaveReturnedWith ( null ) ;
61
61
} ) ;
62
+
63
+ describe ( 'normalizeConsoleBreadcrumb' , ( ) => {
64
+ it ( 'handles console messages with no arguments' , ( ) => {
65
+ const breadcrumb : Breadcrumb = { category : 'console' , message : 'test' } ;
66
+ const actual = HandleScope . normalizeConsoleBreadcrumb ( breadcrumb ) ;
67
+
68
+ expect ( actual ) . toMatchObject ( { category : 'console' , message : 'test' } ) ;
69
+ } ) ;
70
+
71
+ it ( 'handles console messages with empty arguments' , ( ) => {
72
+ const breadcrumb : Breadcrumb = { category : 'console' , message : 'test' , data : { arguments : [ ] } } ;
73
+ const actual = HandleScope . normalizeConsoleBreadcrumb ( breadcrumb ) ;
74
+
75
+ expect ( actual ) . toMatchObject ( { category : 'console' , message : 'test' , data : { arguments : [ ] } } ) ;
76
+ } ) ;
77
+
78
+ it ( 'handles console messages with simple arguments' , ( ) => {
79
+ const breadcrumb : Breadcrumb = {
80
+ category : 'console' ,
81
+ message : 'test' ,
82
+ data : { arguments : [ 1 , 'a' , true , null , undefined ] } ,
83
+ } ;
84
+ const actual = HandleScope . normalizeConsoleBreadcrumb ( breadcrumb ) ;
85
+
86
+ expect ( actual ) . toMatchObject ( {
87
+ category : 'console' ,
88
+ message : 'test' ,
89
+ data : {
90
+ arguments : [ 1 , 'a' , true , null , undefined ] ,
91
+ } ,
92
+ } ) ;
93
+ } ) ;
94
+
95
+ it ( 'truncates large strings' , ( ) => {
96
+ const breadcrumb : Breadcrumb = {
97
+ category : 'console' ,
98
+ message : 'test' ,
99
+ data : {
100
+ arguments : [
101
+ 'a' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE + 10 ) ,
102
+ 'b' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE + 10 ) ,
103
+ ] ,
104
+ } ,
105
+ } ;
106
+ const actual = HandleScope . normalizeConsoleBreadcrumb ( breadcrumb ) ;
107
+
108
+ expect ( actual ) . toMatchObject ( {
109
+ category : 'console' ,
110
+ message : 'test' ,
111
+ data : {
112
+ arguments : [
113
+ `${ 'a' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE ) } …` ,
114
+ `${ 'b' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE ) } …` ,
115
+ ] ,
116
+ _meta : { warnings : [ 'CONSOLE_ARG_TRUNCATED' ] } ,
117
+ } ,
118
+ } ) ;
119
+ } ) ;
120
+
121
+ it ( 'truncates large JSON objects' , ( ) => {
122
+ const breadcrumb : Breadcrumb = {
123
+ category : 'console' ,
124
+ message : 'test' ,
125
+ data : {
126
+ arguments : [
127
+ { aa : 'yes' } ,
128
+ { bb : 'b' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE + 10 ) } ,
129
+ { c : 'c' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE + 10 ) } ,
130
+ ] ,
131
+ } ,
132
+ } ;
133
+ const actual = HandleScope . normalizeConsoleBreadcrumb ( breadcrumb ) ;
134
+
135
+ expect ( actual ) . toMatchObject ( {
136
+ category : 'console' ,
137
+ message : 'test' ,
138
+ data : {
139
+ arguments : [
140
+ { aa : 'yes' } ,
141
+ { bb : `${ 'b' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE - 7 ) } ~~` } ,
142
+ { c : `${ 'c' . repeat ( HandleScope . CONSOLE_ARG_MAX_SIZE - 6 ) } ~~` } ,
143
+ ] ,
144
+ _meta : { warnings : [ 'CONSOLE_ARG_TRUNCATED' ] } ,
145
+ } ,
146
+ } ) ;
147
+ } ) ;
148
+ } ) ;
62
149
} ) ;
0 commit comments