1import nock from 'nock'; 2 3import { getExpoApiBaseUrl } from '../../../api/endpoint'; 4import * as ProjectDevices from '../../project/devices'; 5import { DevelopmentSession } from '../DevelopmentSession'; 6 7const asMock = (fn: any): jest.Mock => fn as jest.Mock; 8 9jest.mock('../../../api/settings', () => ({ 10 APISettings: { 11 isOffline: false, 12 }, 13})); 14jest.mock('../../project/devices', () => ({ 15 getDevicesInfoAsync: jest.fn(), 16})); 17jest.mock('../../../api/user/user'); 18 19describe(`startAsync`, () => { 20 it(`starts a dev session`, async () => { 21 const session = new DevelopmentSession('/', 'http://localhost:19001/'); 22 23 asMock(ProjectDevices.getDevicesInfoAsync).mockResolvedValue({ 24 devices: [{ installationId: '123' }, { installationId: '456' }], 25 }); 26 27 const exp = { 28 name: 'my-app', 29 slug: 'my-app', 30 description: 'my-foo-bar', 31 primaryColor: '#4630eb', 32 }; 33 const runtime = 'native'; 34 const startScope = nock(getExpoApiBaseUrl()) 35 .post('/v2/development-sessions/notify-alive?deviceId=123&deviceId=456') 36 .reply(200, ''); 37 const closeScope = nock(getExpoApiBaseUrl()) 38 .post('/v2/development-sessions/notify-close?deviceId=123&deviceId=456') 39 .reply(200, ''); 40 41 await session.startAsync({ 42 exp, 43 runtime, 44 }); 45 46 await session.closeAsync(); 47 48 expect(ProjectDevices.getDevicesInfoAsync).toHaveBeenCalledTimes(2); 49 expect(startScope.isDone()).toBe(true); 50 expect(closeScope.isDone()).toBe(true); 51 }); 52}); 53