1import { vol } from 'memfs'; 2 3import rnFixture from '../../../prebuild/__tests__/fixtures/react-native-project'; 4import { resolveOptionsAsync } from '../resolveOptions'; 5 6jest.mock('../../../utils/port', () => ({ 7 resolvePortAsync: jest.fn( 8 async (root, { defaultPort, fallbackPort }) => defaultPort ?? fallbackPort 9 ), 10})); 11 12jest.mock('../resolveDevice', () => ({ 13 resolveDeviceAsync: jest.fn(async () => ({ 14 device: { 15 name: 'mock', 16 pid: '123', 17 }, 18 })), 19})); 20 21describe(resolveOptionsAsync, () => { 22 afterEach(() => vol.reset()); 23 24 it(`resolves default options`, async () => { 25 vol.fromJSON(rnFixture, '/'); 26 27 expect(await resolveOptionsAsync('/', {})).toEqual({ 28 apkVariantDirectory: '/android/app/build/outputs/apk/debug', 29 appName: 'app', 30 buildCache: false, 31 buildType: 'debug', 32 device: { 33 device: { 34 name: 'mock', 35 pid: '123', 36 }, 37 }, 38 flavors: [], 39 install: false, 40 launchActivity: 'com.bacon.mydevicefamilyproject/.MainActivity', 41 mainActivity: '.MainActivity', 42 packageName: 'com.bacon.mydevicefamilyproject', 43 port: 8081, 44 shouldStartBundler: true, 45 variant: 'debug', 46 }); 47 }); 48 it(`resolves complex options`, async () => { 49 vol.fromJSON(rnFixture, '/'); 50 51 expect( 52 await resolveOptionsAsync('/', { 53 buildCache: true, 54 bundler: true, 55 device: 'search', 56 install: true, 57 port: 19000, 58 variant: 'firstSecondThird', 59 }) 60 ).toEqual({ 61 apkVariantDirectory: '/android/app/build/outputs/apk/second/third/first', 62 appName: 'app', 63 buildCache: true, 64 buildType: 'first', 65 device: { 66 device: { 67 name: 'mock', 68 pid: '123', 69 }, 70 }, 71 flavors: ['second', 'third'], 72 install: true, 73 launchActivity: 'com.bacon.mydevicefamilyproject/.MainActivity', 74 mainActivity: '.MainActivity', 75 packageName: 'com.bacon.mydevicefamilyproject', 76 port: 19000, 77 shouldStartBundler: true, 78 variant: 'firstSecondThird', 79 }); 80 }); 81}); 82