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