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