@@ -37,14 +37,11 @@ function getSentPayload(): HawkJavaScriptEvent | null {
3737/**
3838 * Single Catcher instance. beforeSend routes by event.title:
3939 *
40- * "pass-through" → return event as-is
41- * "modify" → mutate context, return event
42- * "drop" → return false
43- * "void" → no return (undefined)
44- * "null" → return null
45- * "invalid" → return true
46- * "empty-obj" → return {}
47- * "optional" → delete release, return event
40+ * "modify" → mutate context, return event
41+ * "drop" → return false
42+ * "invalid" → return undefined (no return)
43+ * "optional"→ delete release, return event
44+ * default → return event as-is
4845 */
4946// eslint-disable-next-line @typescript-eslint/no-explicit-any
5047const hawk = new Catcher ( {
@@ -60,17 +57,8 @@ const hawk = new Catcher({
6057
6158 return event ;
6259
63- case 'void' :
64- return ;
65-
66- case 'null' :
67- return null as any ;
68-
6960 case 'invalid' :
70- return true as any ;
71-
72- case 'empty-obj' :
73- return { } as any ;
61+ return ;
7462
7563 case 'optional' :
7664 delete event . release ;
@@ -95,98 +83,47 @@ describe('beforeSend', () => {
9583 warnSpy . mockRestore ( ) ;
9684 } ) ;
9785
98- it ( 'return event → event sent ' , async ( ) => {
86+ it ( 'should send event as-is when returned unchanged ' , async ( ) => {
9987 hawk . send ( new Error ( 'pass-through' ) ) ;
10088 await flush ( ) ;
10189
10290 expect ( socketSendSpy ) . toHaveBeenCalledOnce ( ) ;
103-
104- const payload = getSentPayload ( ) ! ;
105-
106- expect ( payload . title ) . toBe ( 'pass-through' ) ;
107- expect ( payload . backtrace ) . toBeInstanceOf ( Array ) ;
91+ expect ( getSentPayload ( ) ! . title ) . toBe ( 'pass-through' ) ;
10892 } ) ;
10993
110- it ( 'return modified event → sent event with changes ' , async ( ) => {
94+ it ( 'should send modified event when hook mutates and returns it ' , async ( ) => {
11195 hawk . send ( new Error ( 'modify' ) ) ;
11296 await flush ( ) ;
11397
11498 expect ( socketSendSpy ) . toHaveBeenCalledOnce ( ) ;
115-
116- const payload = getSentPayload ( ) ! ;
117-
118- expect ( payload . title ) . toBe ( 'modify' ) ;
119- expect ( payload . context ) . toEqual ( { sanitized : true } ) ;
99+ expect ( getSentPayload ( ) ! . context ) . toEqual ( { sanitized : true } ) ;
120100 } ) ;
121101
122- it ( 'return false → event not sent ' , async ( ) => {
102+ it ( 'should drop event when hook returns false ' , async ( ) => {
123103 hawk . send ( new Error ( 'drop' ) ) ;
124104 await flush ( ) ;
125105
126106 expect ( socketSendSpy ) . not . toHaveBeenCalled ( ) ;
127107 } ) ;
128108
129- it ( 'return undefined → sent original event + warn' , async ( ) => {
130- hawk . send ( new Error ( 'void' ) ) ;
131- await flush ( ) ;
132-
133- expect ( socketSendSpy ) . toHaveBeenCalledOnce ( ) ;
134- expect ( warnSpy ) . toHaveBeenCalledWith (
135- expect . stringContaining ( 'Invalid beforeSend value: (undefined)' ) ,
136- expect . anything ( ) ,
137- expect . anything ( )
138- ) ;
139- expect ( getSentPayload ( ) ! . title ) . toBe ( 'void' ) ;
140- } ) ;
141-
142- it ( 'return null → sent original event + warn' , async ( ) => {
143- hawk . send ( new Error ( 'null' ) ) ;
144- await flush ( ) ;
145-
146- expect ( socketSendSpy ) . toHaveBeenCalledOnce ( ) ;
147- expect ( warnSpy ) . toHaveBeenCalledWith (
148- expect . stringContaining ( 'Invalid beforeSend value: (null)' ) ,
149- expect . anything ( ) ,
150- expect . anything ( )
151- ) ;
152- expect ( getSentPayload ( ) ! . title ) . toBe ( 'null' ) ;
153- } ) ;
154-
155- it ( 'return true → sent original event + warn' , async ( ) => {
109+ it ( 'should send original event and warn when hook returns invalid value' , async ( ) => {
156110 hawk . send ( new Error ( 'invalid' ) ) ;
157111 await flush ( ) ;
158112
159113 expect ( socketSendSpy ) . toHaveBeenCalledOnce ( ) ;
160- expect ( warnSpy ) . toHaveBeenCalledWith (
161- expect . stringContaining ( 'Invalid beforeSend value:' ) ,
162- expect . anything ( ) ,
163- expect . anything ( )
164- ) ;
165114 expect ( getSentPayload ( ) ! . title ) . toBe ( 'invalid' ) ;
166- } ) ;
167-
168- it ( 'return {} → sent original event + warn' , async ( ) => {
169- hawk . send ( new Error ( 'empty-obj' ) ) ;
170- await flush ( ) ;
171-
172- expect ( socketSendSpy ) . toHaveBeenCalledOnce ( ) ;
173115 expect ( warnSpy ) . toHaveBeenCalledWith (
174116 expect . stringContaining ( 'Invalid beforeSend value:' ) ,
175117 expect . anything ( ) ,
176118 expect . anything ( )
177119 ) ;
178- expect ( getSentPayload ( ) ! . title ) . toBe ( 'empty-obj' ) ;
179120 } ) ;
180121
181- it ( 'delete optional fields → sent event without them ' , async ( ) => {
122+ it ( 'should send event without deleted optional fields ' , async ( ) => {
182123 hawk . send ( new Error ( 'optional' ) ) ;
183124 await flush ( ) ;
184125
185126 expect ( socketSendSpy ) . toHaveBeenCalledOnce ( ) ;
186-
187- const payload = getSentPayload ( ) ! ;
188-
189- expect ( payload . title ) . toBe ( 'optional' ) ;
190- expect ( payload . release ) . toBeUndefined ( ) ;
127+ expect ( getSentPayload ( ) ! . release ) . toBeUndefined ( ) ;
191128 } ) ;
192129} ) ;
0 commit comments