1import { vol } from 'memfs'; 2 3import { 4 ensureValidPlatforms, 5 resolvePlatformOption, 6 resolveSkipDependencyUpdate, 7 resolvePackageManagerOptions, 8 resolveTemplateOption, 9} from '../resolveOptions'; 10 11describe(resolvePackageManagerOptions, () => { 12 it(`resolves`, () => { 13 expect(resolvePackageManagerOptions({ '--yarn': true })).toEqual({ 14 npm: undefined, 15 pnpm: undefined, 16 yarn: true, 17 }); 18 }); 19 it(`asserts mutually exclusive arguments`, () => { 20 expect(() => resolvePackageManagerOptions({ '--npm': true, '--pnpm': true })).toThrow(); 21 expect(() => resolvePackageManagerOptions({ '--no-install': true, '--yarn': true })).toThrow(); 22 expect(() => 23 resolvePackageManagerOptions({ 24 '--npm': true, 25 '--pnpm': true, 26 '--no-install': true, 27 '--yarn': true, 28 }) 29 ).toThrow(); 30 }); 31}); 32 33describe(resolvePlatformOption, () => { 34 const platform = process.platform; 35 36 afterEach(() => { 37 Object.defineProperty(process, 'platform', { 38 value: platform, 39 }); 40 }); 41 42 it('returns the correct platforms', () => { 43 expect(resolvePlatformOption('ios')).toEqual(['ios']); 44 expect(resolvePlatformOption('android')).toEqual(['android']); 45 }); 46 it('returns the correct platforms (darwin)', () => { 47 Object.defineProperty(process, 'platform', { 48 value: 'darwin', 49 }); 50 51 expect(resolvePlatformOption('all')).toEqual(['android', 'ios']); 52 }); 53 it('returns the correct platforms (win32)', () => { 54 Object.defineProperty(process, 'platform', { 55 value: 'win32', 56 }); 57 58 expect(resolvePlatformOption('all')).toEqual(['android']); 59 }); 60 it('accepts unknown platforms', () => { 61 expect(resolvePlatformOption('foo')).toEqual(['foo']); 62 }); 63}); 64 65describe(resolveSkipDependencyUpdate, () => { 66 it('splits dependencies', () => { 67 expect(resolveSkipDependencyUpdate(undefined)).toEqual([]); 68 expect(resolveSkipDependencyUpdate('')).toEqual([]); 69 expect(resolveSkipDependencyUpdate('foo')).toEqual(['foo']); 70 expect(resolveSkipDependencyUpdate('foo,bar')).toEqual(['foo', 'bar']); 71 }); 72}); 73 74describe(resolveTemplateOption, () => { 75 beforeAll(() => { 76 vol.fromJSON({ 77 '/foo': '', 78 }); 79 }); 80 afterAll(() => { 81 vol.reset(); 82 }); 83 it('resolves a URL template', () => { 84 expect(resolveTemplateOption('http://foo')).toEqual('http://foo'); 85 }); 86 it('asserts a missing file path template', () => { 87 expect(() => resolveTemplateOption('bacon/bar')).toThrowError( 88 /template file does not exist: .*bacon\/bar/ 89 ); 90 }); 91 it('resolves a file path template', () => { 92 expect(resolveTemplateOption('/foo')).toEqual('/foo'); 93 }); 94}); 95 96describe(ensureValidPlatforms, () => { 97 const platform = process.platform; 98 const warning = console.warn; 99 100 beforeAll(() => { 101 console.warn = jest.fn(); 102 }); 103 afterAll(() => { 104 console.warn = warning; 105 }); 106 afterEach(() => { 107 Object.defineProperty(process, 'platform', { 108 value: platform, 109 }); 110 }); 111 it(`bails on windows if only ios is passed`, async () => { 112 Object.defineProperty(process, 'platform', { 113 value: 'win32', 114 }); 115 expect(ensureValidPlatforms(['ios', 'android'])).toStrictEqual(['android']); 116 }); 117 it(`allows ios on all platforms except windows`, async () => { 118 Object.defineProperty(process, 'platform', { 119 value: 'other', 120 }); 121 expect(ensureValidPlatforms(['ios', 'android'])).toStrictEqual(['ios', 'android']); 122 }); 123}); 124