|
1 | | -import type { Event as SentryEvent, Exception, StackFrame, Stacktrace } from '@sentry/types'; |
| 1 | +import type { Event as SentryEvent, EventProcessor, Exception, Hub, StackFrame, Stacktrace } from '@sentry/types'; |
2 | 2 |
|
3 | | -import { _shouldDropEvent } from '../src/dedupe'; |
| 3 | +import { _shouldDropEvent, Dedupe } from '../src/dedupe'; |
4 | 4 |
|
5 | 5 | type EventWithException = SentryEvent & { |
6 | 6 | exception: { |
@@ -175,4 +175,48 @@ describe('Dedupe', () => { |
175 | 175 | expect(_shouldDropEvent(eventB, eventC)).toBe(false); |
176 | 176 | }); |
177 | 177 | }); |
| 178 | + |
| 179 | + describe('setupOnce', () => { |
| 180 | + let dedupeFunc: EventProcessor; |
| 181 | + |
| 182 | + beforeEach(function () { |
| 183 | + const integration = new Dedupe(); |
| 184 | + const addGlobalEventProcessor = (callback: EventProcessor) => { |
| 185 | + dedupeFunc = callback; |
| 186 | + }; |
| 187 | + |
| 188 | + const getCurrentHub = () => { |
| 189 | + return { |
| 190 | + getIntegration() { |
| 191 | + return integration; |
| 192 | + }, |
| 193 | + } as unknown as Hub; |
| 194 | + }; |
| 195 | + |
| 196 | + integration.setupOnce(addGlobalEventProcessor, getCurrentHub); |
| 197 | + }); |
| 198 | + |
| 199 | + it('ignores consecutive errors', () => { |
| 200 | + expect(dedupeFunc(clone(exceptionEvent), {})).not.toBeNull(); |
| 201 | + expect(dedupeFunc(clone(exceptionEvent), {})).toBeNull(); |
| 202 | + expect(dedupeFunc(clone(exceptionEvent), {})).toBeNull(); |
| 203 | + }); |
| 204 | + |
| 205 | + it('ignores transactions between errors', () => { |
| 206 | + expect(dedupeFunc(clone(exceptionEvent), {})).not.toBeNull(); |
| 207 | + expect( |
| 208 | + dedupeFunc( |
| 209 | + { |
| 210 | + event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', |
| 211 | + message: 'someMessage', |
| 212 | + transaction: 'wat', |
| 213 | + type: 'transaction', |
| 214 | + }, |
| 215 | + {}, |
| 216 | + ), |
| 217 | + ).not.toBeNull(); |
| 218 | + expect(dedupeFunc(clone(exceptionEvent), {})).toBeNull(); |
| 219 | + expect(dedupeFunc(clone(exceptionEvent), {})).toBeNull(); |
| 220 | + }); |
| 221 | + }); |
178 | 222 | }); |
0 commit comments