|
| 1 | +import { RewriteFrames } from '@sentry/integrations'; |
| 2 | +import { Integration } from '@sentry/types'; |
| 3 | + |
| 4 | +import { addIntegration, UserFunctionIntegrations } from '../src/utils/userIntegrations'; |
| 5 | + |
| 6 | +const testIntegration = new RewriteFrames(); |
| 7 | + |
| 8 | +describe('user integrations without any integrations', () => { |
| 9 | + test('as an array', () => { |
| 10 | + const userIntegrations: Integration[] = []; |
| 11 | + // Should get a single integration |
| 12 | + let finalIntegrations = addIntegration(testIntegration, userIntegrations); |
| 13 | + expect(finalIntegrations).toBeInstanceOf(Array); |
| 14 | + finalIntegrations = finalIntegrations as Integration[]; |
| 15 | + expect(finalIntegrations).toHaveLength(1); |
| 16 | + expect(finalIntegrations[0]).toMatchObject(testIntegration); |
| 17 | + }); |
| 18 | + |
| 19 | + test('as a function', () => { |
| 20 | + const userIntegrationFnc: UserFunctionIntegrations = (): Integration[] => []; |
| 21 | + // Should get a single integration |
| 22 | + const integrationWrapper = addIntegration(testIntegration, userIntegrationFnc); |
| 23 | + expect(integrationWrapper).toBeInstanceOf(Function); |
| 24 | + const finalIntegrations = (integrationWrapper as UserFunctionIntegrations)([]); |
| 25 | + expect(finalIntegrations).toHaveLength(1); |
| 26 | + expect(finalIntegrations[0]).toMatchObject(testIntegration); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +describe('user integrations with integrations', () => { |
| 31 | + test('as an array', () => { |
| 32 | + const userIntegrations = [new RewriteFrames()]; |
| 33 | + // Should get the same array (with no patches) |
| 34 | + const finalIntegrations = addIntegration(testIntegration, userIntegrations); |
| 35 | + expect(finalIntegrations).toMatchObject(userIntegrations); |
| 36 | + }); |
| 37 | + |
| 38 | + test('as a function', () => { |
| 39 | + const userIntegrations = [new RewriteFrames()]; |
| 40 | + const integrationsFnc: UserFunctionIntegrations = (_integrations: Integration[]): Integration[] => { |
| 41 | + return userIntegrations; |
| 42 | + }; |
| 43 | + // Should get a function that returns the test integration |
| 44 | + let finalIntegrations = addIntegration(testIntegration, integrationsFnc); |
| 45 | + expect(typeof finalIntegrations === 'function').toBe(true); |
| 46 | + expect(finalIntegrations).toBeInstanceOf(Function); |
| 47 | + finalIntegrations = finalIntegrations as UserFunctionIntegrations; |
| 48 | + expect(finalIntegrations([])).toMatchObject(userIntegrations); |
| 49 | + }); |
| 50 | +}); |
0 commit comments