|
1 |
| -import type { Client, Event } from '@sentry/core'; |
| 1 | +import { type Client, type Event, getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/core'; |
2 | 2 |
|
3 | 3 | import { expoContextIntegration, OTA_UPDATES_CONTEXT_KEY } from '../../src/js/integrations/expocontext';
|
4 | 4 | import * as environment from '../../src/js/utils/environment';
|
5 | 5 | import type { ExpoUpdates } from '../../src/js/utils/expoglobalobject';
|
6 | 6 | import { getExpoDevice } from '../../src/js/utils/expomodules';
|
7 | 7 | import * as expoModules from '../../src/js/utils/expomodules';
|
| 8 | +import { setupTestClient } from '../mocks/client'; |
| 9 | +import { NATIVE } from '../mockWrapper'; |
8 | 10 |
|
| 11 | +jest.mock('../../src/js/wrapper', () => jest.requireActual('../mockWrapper')); |
9 | 12 | jest.mock('../../src/js/utils/expomodules');
|
10 | 13 |
|
11 | 14 | describe('Expo Context Integration', () => {
|
12 | 15 | afterEach(() => {
|
13 | 16 | jest.clearAllMocks();
|
| 17 | + |
| 18 | + getCurrentScope().clear(); |
| 19 | + getIsolationScope().clear(); |
| 20 | + getGlobalScope().clear(); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('Set Native Context after init()', () => { |
| 24 | + beforeEach(() => { |
| 25 | + jest.spyOn(expoModules, 'getExpoUpdates').mockReturnValue({ |
| 26 | + updateId: '123', |
| 27 | + channel: 'default', |
| 28 | + runtimeVersion: '1.0.0', |
| 29 | + checkAutomatically: 'always', |
| 30 | + emergencyLaunchReason: 'some reason', |
| 31 | + launchDuration: 1000, |
| 32 | + createdAt: new Date('2021-01-01T00:00:00.000Z'), |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('calls setContext when native enabled', () => { |
| 37 | + jest.spyOn(environment, 'isExpo').mockReturnValue(true); |
| 38 | + jest.spyOn(environment, 'isExpoGo').mockReturnValue(false); |
| 39 | + |
| 40 | + setupTestClient({ enableNative: true, integrations: [expoContextIntegration()] }); |
| 41 | + |
| 42 | + expect(NATIVE.setContext).toHaveBeenCalledWith( |
| 43 | + OTA_UPDATES_CONTEXT_KEY, |
| 44 | + expect.objectContaining({ |
| 45 | + update_id: '123', |
| 46 | + channel: 'default', |
| 47 | + runtime_version: '1.0.0', |
| 48 | + }), |
| 49 | + ); |
| 50 | + }); |
| 51 | + |
| 52 | + it('does not call setContext when native disabled', () => { |
| 53 | + jest.spyOn(environment, 'isExpo').mockReturnValue(true); |
| 54 | + jest.spyOn(environment, 'isExpoGo').mockReturnValue(false); |
| 55 | + |
| 56 | + setupTestClient({ enableNative: false, integrations: [expoContextIntegration()] }); |
| 57 | + |
| 58 | + expect(NATIVE.setContext).not.toHaveBeenCalled(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('does not call setContext when not expo', () => { |
| 62 | + jest.spyOn(environment, 'isExpo').mockReturnValue(false); |
| 63 | + jest.spyOn(environment, 'isExpoGo').mockReturnValue(false); |
| 64 | + |
| 65 | + setupTestClient({ enableNative: true, integrations: [expoContextIntegration()] }); |
| 66 | + |
| 67 | + expect(NATIVE.setContext).not.toHaveBeenCalled(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('does not call setContext when expo go', () => { |
| 71 | + jest.spyOn(environment, 'isExpo').mockReturnValue(true); |
| 72 | + jest.spyOn(environment, 'isExpoGo').mockReturnValue(true); |
| 73 | + |
| 74 | + setupTestClient({ enableNative: true, integrations: [expoContextIntegration()] }); |
| 75 | + |
| 76 | + expect(NATIVE.setContext).not.toHaveBeenCalled(); |
| 77 | + }); |
14 | 78 | });
|
15 | 79 |
|
16 | 80 | describe('Non Expo App', () => {
|
|
0 commit comments