Skip to content

Commit 5dc939f

Browse files
Finish expo context integration tests
1 parent 19c9c24 commit 5dc939f

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/js/integrations/expocontext.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DeviceContext, Event, EventProcessor, Hub, Integration, OsContext } from '@sentry/types';
2+
23
import { getExpoDevice } from '../utils/expomodules';
34

45
/** Load device context from expo modules. */

test/integrations/expocontext.test.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,38 @@ describe('Expo Context Integration', () => {
3333
});
3434

3535
it('adds expo device context', async () => {
36+
(getExpoDevice as jest.Mock).mockReturnValue({
37+
deviceName: 'test device name',
38+
isDevice: true,
39+
modelName: 'test model name',
40+
manufacturer: 'test manufacturer',
41+
totalMemory: 1000,
42+
});
43+
const actualEvent = await executeIntegrationFor({});
3644

45+
expect(actualEvent.contexts?.device).toStrictEqual({
46+
name: 'test device name',
47+
simulator: false,
48+
model: 'test model name',
49+
manufacturer: 'test manufacturer',
50+
memory_size: 1000,
51+
});
3752
});
3853

39-
it('adds expo os context', async () => { });
54+
it('adds expo os context', async () => {
55+
(getExpoDevice as jest.Mock).mockReturnValue({
56+
osName: 'test os name',
57+
osBuildId: 'test os build id',
58+
osVersion: 'test os version',
59+
});
60+
const actualEvent = await executeIntegrationFor({});
61+
62+
expect(actualEvent.contexts?.os).toStrictEqual({
63+
name: 'test os name',
64+
build: 'test os build id',
65+
version: 'test os version',
66+
});
67+
});
4068

4169
function executeIntegrationFor(mockedEvent: Event): Promise<Event | null> {
4270
return new Promise((resolve, reject) => {

test/sdk.test.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import type { ReactNativeClientOptions } from '../src/js/options';
7575
import { configureScope, flush, init, withScope } from '../src/js/sdk';
7676
import { ReactNativeTracing, ReactNavigationInstrumentation } from '../src/js/tracing';
7777
import { makeNativeTransport } from '../src/js/transports/native';
78-
import { getDefaultEnvironment, notWeb } from '../src/js/utils/environment';
78+
import { getDefaultEnvironment, isExpoGo, notWeb } from '../src/js/utils/environment';
7979
import { firstArg, secondArg } from './testutils';
8080

8181
const mockedInitAndBind = initAndBind as jest.MockedFunction<typeof initAndBind>;
@@ -695,6 +695,16 @@ describe('Tests the SDK functionality', () => {
695695
);
696696
});
697697
});
698+
699+
it('adds expo context integration if expo go is detected', () => {
700+
(isExpoGo as jest.Mock).mockImplementation(() => true);
701+
init({});
702+
703+
const actualOptions = mockedInitAndBind.mock.calls[0][secondArg] as ReactNativeClientOptions;
704+
const actualIntegrations = actualOptions.integrations;
705+
706+
expect(actualIntegrations).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'ExpoContext' })]));
707+
});
698708
});
699709

700710
function getMockClient(): MockedClient {

0 commit comments

Comments
 (0)