1import { getConfig } from '@expo/config'; 2 3import { asMock } from '../../__tests__/asMock'; 4import { resolveOptionsAsync } from '../resolveOptions'; 5 6jest.mock('@expo/config', () => ({ 7 getConfig: jest.fn(() => ({ 8 pkg: {}, 9 exp: { 10 sdkVersion: '45.0.0', 11 name: 'my-app', 12 slug: 'my-app', 13 }, 14 })), 15})); 16 17describe(resolveOptionsAsync, () => { 18 it(`asserts unknown platform`, async () => { 19 await expect(resolveOptionsAsync('/', { '--platform': ['foobar'] })).rejects.toThrow( 20 /^Unsupported platform "foobar"\./ 21 ); 22 }); 23 24 it(`asserts not-configured platform`, async () => { 25 await expect(resolveOptionsAsync('/', { '--platform': ['web'] })).rejects.toThrow( 26 /^Platform "web" is not configured to use the Metro bundler in the project Expo config\./ 27 ); 28 }); 29 30 it(`allows multiple platform flags`, async () => { 31 await expect( 32 resolveOptionsAsync('/', { '--platform': ['android', 'ios'] }) 33 ).resolves.toMatchObject({ 34 platforms: ['android', 'ios'], 35 }); 36 }); 37 38 it(`filters duplicated platform flags`, async () => { 39 await expect( 40 resolveOptionsAsync('/', { '--platform': ['android', 'android', 'ios', 'ios'] }) 41 ).resolves.toMatchObject({ 42 platforms: ['android', 'ios'], 43 }); 44 }); 45 46 it(`filters duplicated platform flags including all`, async () => { 47 await expect( 48 resolveOptionsAsync('/', { '--platform': ['android', 'all'] }) 49 ).resolves.toMatchObject({ 50 platforms: ['android', 'ios'], 51 }); 52 }); 53 54 it(`parses qualified options`, async () => { 55 await expect( 56 resolveOptionsAsync('/', { 57 '--output-dir': 'foobar', 58 '--platform': ['android'], 59 '--clear': true, 60 '--dev': true, 61 '--dump-assetmap': true, 62 '--dump-sourcemap': true, 63 '--max-workers': 2, 64 }) 65 ).resolves.toEqual({ 66 clear: true, 67 dev: true, 68 minify: true, 69 dumpAssetmap: true, 70 dumpSourcemap: true, 71 maxWorkers: 2, 72 outputDir: 'foobar', 73 platforms: ['android'], 74 }); 75 }); 76 77 it(`parses default options`, async () => { 78 await expect(resolveOptionsAsync('/', {})).resolves.toEqual({ 79 clear: false, 80 dev: false, 81 minify: true, 82 dumpAssetmap: false, 83 dumpSourcemap: false, 84 maxWorkers: undefined, 85 outputDir: 'dist', 86 platforms: ['ios', 'android'], 87 }); 88 }); 89 it(`parses default options with web enabled`, async () => { 90 asMock(getConfig).mockReturnValueOnce({ 91 // @ts-expect-error 92 exp: { web: { bundler: 'metro' } }, 93 }); 94 await expect(resolveOptionsAsync('/', {})).resolves.toEqual( 95 expect.objectContaining({ 96 platforms: ['ios', 'android', 'web'], 97 }) 98 ); 99 }); 100}); 101