|
1 | 1 | import { Hub, captureCheckIn, makeMain, setCurrentClient } from '@sentry/core'; |
2 | | -import type { Client, Integration } from '@sentry/types'; |
| 2 | +import type { Client, Integration, IntegrationFnResult } from '@sentry/types'; |
3 | 3 |
|
4 | 4 | import { installedIntegrations } from '../../src/integration'; |
5 | 5 | import { initAndBind } from '../../src/sdk'; |
@@ -35,6 +35,53 @@ describe('SDK', () => { |
35 | 35 | expect((integrations[0].setupOnce as jest.Mock).mock.calls.length).toBe(1); |
36 | 36 | expect((integrations[1].setupOnce as jest.Mock).mock.calls.length).toBe(1); |
37 | 37 | }); |
| 38 | + |
| 39 | + test('calls hooks in the correct order', () => { |
| 40 | + const list: string[] = []; |
| 41 | + |
| 42 | + const integration1 = { |
| 43 | + name: 'integration1', |
| 44 | + setupOnce: jest.fn(() => list.push('setupOnce1')), |
| 45 | + afterAllSetup: jest.fn(() => list.push('afterAllSetup1')), |
| 46 | + } satisfies IntegrationFnResult; |
| 47 | + |
| 48 | + const integration2 = { |
| 49 | + name: 'integration2', |
| 50 | + setupOnce: jest.fn(() => list.push('setupOnce2')), |
| 51 | + setup: jest.fn(() => list.push('setup2')), |
| 52 | + afterAllSetup: jest.fn(() => list.push('afterAllSetup2')), |
| 53 | + } satisfies IntegrationFnResult; |
| 54 | + |
| 55 | + const integration3 = { |
| 56 | + name: 'integration3', |
| 57 | + setupOnce: jest.fn(() => list.push('setupOnce3')), |
| 58 | + setup: jest.fn(() => list.push('setup3')), |
| 59 | + } satisfies IntegrationFnResult; |
| 60 | + |
| 61 | + const integrations: Integration[] = [integration1, integration2, integration3]; |
| 62 | + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, integrations }); |
| 63 | + initAndBind(TestClient, options); |
| 64 | + |
| 65 | + expect(integration1.setupOnce).toHaveBeenCalledTimes(1); |
| 66 | + expect(integration2.setupOnce).toHaveBeenCalledTimes(1); |
| 67 | + expect(integration3.setupOnce).toHaveBeenCalledTimes(1); |
| 68 | + |
| 69 | + expect(integration2.setup).toHaveBeenCalledTimes(1); |
| 70 | + expect(integration3.setup).toHaveBeenCalledTimes(1); |
| 71 | + |
| 72 | + expect(integration1.afterAllSetup).toHaveBeenCalledTimes(1); |
| 73 | + expect(integration2.afterAllSetup).toHaveBeenCalledTimes(1); |
| 74 | + |
| 75 | + expect(list).toEqual([ |
| 76 | + 'setupOnce1', |
| 77 | + 'setupOnce2', |
| 78 | + 'setup2', |
| 79 | + 'setupOnce3', |
| 80 | + 'setup3', |
| 81 | + 'afterAllSetup1', |
| 82 | + 'afterAllSetup2', |
| 83 | + ]); |
| 84 | + }); |
38 | 85 | }); |
39 | 86 | }); |
40 | 87 |
|
|
0 commit comments