1import os from 'os'; 2 3import { 4 getContext, 5 getRudderAnalyticsClient, 6 logEventAsync, 7 resetInternalStateForTesting, 8 setUserDataAsync, 9} from '../rudderstackClient'; 10 11jest.mock('ci-info', () => ({ isCI: true, isPR: true, name: 'GitHub Actions' })); 12 13jest.mock('@expo/rudder-sdk-node'); 14 15describe(logEventAsync, () => { 16 beforeEach(() => { 17 resetInternalStateForTesting(); 18 }); 19 20 it('logs when the user has been identified', async () => { 21 await setUserDataAsync('fake', {}); 22 await logEventAsync('Start Project'); 23 expect(getRudderAnalyticsClient().track).toHaveBeenCalledWith({ 24 anonymousId: expect.any(String), 25 context: getContext(), 26 event: 'Start Project', 27 properties: { source: 'expo', source_version: undefined }, 28 userId: 'fake', 29 }); 30 }); 31 32 it('does not log when the user has not been identified', async () => { 33 await logEventAsync('Start Project'); 34 expect(getRudderAnalyticsClient().track).not.toHaveBeenCalled(); 35 }); 36}); 37 38describe(getContext, () => { 39 const originalVersion = process.env.__EXPO_VERSION; 40 const knownPlatformNames = { 41 darwin: 'Mac', 42 linux: 'Linux', 43 win32: 'Windows', 44 }; 45 46 beforeEach(() => { 47 delete process.env.__EXPO_VERSION; 48 }); 49 50 afterAll(() => { 51 process.env.__EXPO_VERSION = originalVersion; 52 }); 53 54 it('contains os name and version', () => { 55 expect(getContext().os).toMatchObject({ 56 name: knownPlatformNames[os.platform()] || os.platform(), 57 version: os.release(), 58 }); 59 }); 60 61 it('contains device type and model', () => { 62 expect(getContext().device).toMatchObject({ 63 type: knownPlatformNames[os.platform()] || os.platform(), 64 model: knownPlatformNames[os.platform()] || os.platform(), 65 }); 66 }); 67 68 it('contains app name and version', () => { 69 process.env.__EXPO_VERSION = '1337'; 70 expect(getContext().app).toMatchObject({ 71 name: 'expo', 72 version: '1337', 73 }); 74 }); 75 76 it('contains ci name and if its executed from PR', () => { 77 expect(getContext().ci).toMatchObject({ 78 name: 'GitHub Actions', 79 isPr: true, 80 }); 81 }); 82}); 83