@@ -2,24 +2,41 @@ import { EventProcessor } from '@sentry/types';
2
2
3
3
import { InboundFilters , InboundFiltersOptions } from '../../../src/integrations/inboundfilters' ;
4
4
5
- /** JSDoc */
5
+ /**
6
+ * Creates an instance of the InboundFilters integration and returns
7
+ * the event processor that the InboundFilters integration creates.
8
+ *
9
+ * To test the InboundFilters integration, call this function and assert on
10
+ * how the event processor handles an event. For example, if you set up the
11
+ * InboundFilters to filter out an SOME_EXCEPTION_EVENT.
12
+ *
13
+ * ```
14
+ * // some options that cause SOME_EXCEPTION_EVENT to be filtered
15
+ * const eventProcessor = createInboundFiltersEventProcessor(options);
16
+ *
17
+ * expect(eventProcessor(SOME_EXCEPTION_EVENT)).toBe(null);
18
+ * ```
19
+ *
20
+ * @param options options passed into the InboundFilters integration
21
+ * @param clientOptions options passed into the mock Sentry client
22
+ */
6
23
function createInboundFiltersEventProcessor (
7
24
options : Partial < InboundFiltersOptions > = { } ,
8
25
clientOptions : Partial < InboundFiltersOptions > = { } ,
9
26
) : EventProcessor {
10
27
const eventProcessors : EventProcessor [ ] = [ ] ;
11
- const inboundFilters = new InboundFilters ( options ) ;
28
+ const inboundFiltersInstance = new InboundFilters ( options ) ;
12
29
13
- function addGlobalEventProcessor ( callback : EventProcessor ) : void {
14
- eventProcessors . push ( callback ) ;
30
+ function addGlobalEventProcessor ( processor : EventProcessor ) : void {
31
+ eventProcessors . push ( processor ) ;
15
32
expect ( eventProcessors ) . toHaveLength ( 1 ) ;
16
33
}
17
34
18
35
function getCurrentHub ( ) : any {
19
36
return {
20
37
getIntegration ( _integration : any ) : any {
21
38
// pretend integration is enabled
22
- return inboundFilters ;
39
+ return inboundFiltersInstance ;
23
40
} ,
24
41
getClient ( ) : any {
25
42
return {
@@ -29,13 +46,12 @@ function createInboundFiltersEventProcessor(
29
46
} ;
30
47
}
31
48
32
- inboundFilters . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
33
-
49
+ inboundFiltersInstance . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
34
50
return eventProcessors [ 0 ] ;
35
51
}
36
52
37
53
describe ( 'InboundFilters' , ( ) => {
38
- describe ( 'isSentryError ' , ( ) => {
54
+ describe ( '_isSentryError ' , ( ) => {
39
55
it ( 'should work as expected' , ( ) => {
40
56
const eventProcessor = createInboundFiltersEventProcessor ( ) ;
41
57
expect ( eventProcessor ( MESSAGE_EVENT ) ) . toBe ( MESSAGE_EVENT ) ;
@@ -81,7 +97,7 @@ describe('InboundFilters', () => {
81
97
expect ( eventProcessor ( MESSAGE_EVENT_2 ) ) . toBe ( MESSAGE_EVENT_2 ) ;
82
98
} ) ;
83
99
84
- it ( 'uses message when both, message and exception are available' , ( ) => {
100
+ it ( 'prefers message when both message and exception are available' , ( ) => {
85
101
const eventProcessor = createInboundFiltersEventProcessor ( {
86
102
ignoreErrors : [ / c a p t u r e M e s s a g e / ] ,
87
103
} ) ;
@@ -102,11 +118,11 @@ describe('InboundFilters', () => {
102
118
103
119
it ( 'uses default filters' , ( ) => {
104
120
const eventProcessor = createInboundFiltersEventProcessor ( ) ;
105
- expect ( eventProcessor ( DEFAULT_EVENT ) ) . toBe ( null ) ;
121
+ expect ( eventProcessor ( SCRIPT_ERROR_EVENT ) ) . toBe ( null ) ;
106
122
} ) ;
107
123
108
124
describe ( 'on exception' , ( ) => {
109
- it ( 'uses exceptions data when message is unavailable' , ( ) => {
125
+ it ( 'uses exception data when message is unavailable' , ( ) => {
110
126
const eventProcessor = createInboundFiltersEventProcessor ( {
111
127
ignoreErrors : [ 'SyntaxError: unidentified ? at line 1337' ] ,
112
128
} ) ;
@@ -131,19 +147,18 @@ describe('InboundFilters', () => {
131
147
132
148
describe ( 'denyUrls/allowUrls' , ( ) => {
133
149
it ( 'should filter captured message based on its stack trace using string filter' , ( ) => {
134
- const eventProcessorBoth = createInboundFiltersEventProcessor ( {
135
- allowUrls : [ 'https://awesome-analytics.io' ] ,
150
+ const eventProcessorDeny = createInboundFiltersEventProcessor ( {
136
151
denyUrls : [ 'https://awesome-analytics.io' ] ,
137
152
} ) ;
138
- expect ( eventProcessorBoth ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
139
- const eventProcessorAllow = createInboundFiltersEventProcessor ( {
153
+ expect ( eventProcessorDeny ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
154
+ } ) ;
155
+
156
+ it ( 'should allow denyUrls to take precedence' , ( ) => {
157
+ const eventProcessorBoth = createInboundFiltersEventProcessor ( {
140
158
allowUrls : [ 'https://awesome-analytics.io' ] ,
141
- } ) ;
142
- expect ( eventProcessorAllow ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( MESSAGE_EVENT_WITH_STACKTRACE ) ;
143
- const eventProcessorDeny = createInboundFiltersEventProcessor ( {
144
159
denyUrls : [ 'https://awesome-analytics.io' ] ,
145
160
} ) ;
146
- expect ( eventProcessorDeny ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
161
+ expect ( eventProcessorBoth ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
147
162
} ) ;
148
163
149
164
it ( 'should filter captured message based on its stack trace using regexp filter' , ( ) => {
@@ -167,7 +182,7 @@ describe('InboundFilters', () => {
167
182
expect ( eventProcessor ( EXCEPTION_EVENT_WITH_FRAMES ) ) . toBe ( null ) ;
168
183
} ) ;
169
184
170
- it ( 'should filter captured exceptions based on its stack trace using regexp filter' , ( ) => {
185
+ it ( 'should filter captured exception based on its stack trace using regexp filter' , ( ) => {
171
186
const eventProcessor = createInboundFiltersEventProcessor ( {
172
187
denyUrls : [ / a w e s o m e - a n a l y t i c s \. i o / ] ,
173
188
} ) ;
@@ -199,14 +214,14 @@ describe('InboundFilters', () => {
199
214
const eventProcessor = createInboundFiltersEventProcessor ( {
200
215
denyUrls : [ 'https://awesome-analytics.io/some/file.js' ] ,
201
216
} ) ;
202
- expect ( eventProcessor ( MESSAGE_EVENT_WITH_ANON_FRAME ) ) . toBe ( null ) ;
217
+ expect ( eventProcessor ( MESSAGE_EVENT_WITH_ANON_LAST_FRAME ) ) . toBe ( null ) ;
203
218
} ) ;
204
219
205
220
it ( 'should search for script names when the last frame is from native code' , ( ) => {
206
221
const eventProcessor = createInboundFiltersEventProcessor ( {
207
222
denyUrls : [ 'https://awesome-analytics.io/some/file.js' ] ,
208
223
} ) ;
209
- expect ( eventProcessor ( MESSAGE_EVENT_WITH_NATIVE_FRAME ) ) . toBe ( null ) ;
224
+ expect ( eventProcessor ( MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME ) ) . toBe ( null ) ;
210
225
} ) ;
211
226
} ) ;
212
227
} ) ;
@@ -234,7 +249,7 @@ const MESSAGE_EVENT_WITH_STACKTRACE = {
234
249
} ,
235
250
} ;
236
251
237
- const MESSAGE_EVENT_WITH_ANON_FRAME = {
252
+ const MESSAGE_EVENT_WITH_ANON_LAST_FRAME = {
238
253
message : 'any' ,
239
254
stacktrace : {
240
255
frames : [
@@ -245,7 +260,7 @@ const MESSAGE_EVENT_WITH_ANON_FRAME = {
245
260
} ,
246
261
} ;
247
262
248
- const MESSAGE_EVENT_WITH_NATIVE_FRAME = {
263
+ const MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME = {
249
264
message : 'any' ,
250
265
stacktrace : {
251
266
frames : [
@@ -296,7 +311,7 @@ const SENTRY_EVENT = {
296
311
} ,
297
312
} ;
298
313
299
- const DEFAULT_EVENT = {
314
+ const SCRIPT_ERROR_EVENT = {
300
315
exception : {
301
316
values : [
302
317
{
0 commit comments