1import { resolveArgsAsync } from '../resolveOptions'; 2 3describe(resolveArgsAsync, () => { 4 it(`asserts invalid flags`, async () => { 5 await expect(resolveArgsAsync(['-g', '--bacon'])).rejects.toThrow(/Unexpected: -g, --bacon/); 6 }); 7 it(`prevents bad combos`, async () => { 8 await expect(resolveArgsAsync(['--npm', '--yarn'])).rejects.toThrow( 9 /Specify at most one of: --npm, --pnpm, --yarn/ 10 ); 11 await expect(resolveArgsAsync(['--npm', '--pnpm', '--yarn'])).rejects.toThrow( 12 /Specify at most one of: --npm, --pnpm, --yarn/ 13 ); 14 }); 15 it(`allows known values`, async () => { 16 const result = await resolveArgsAsync([ 17 'bacon', 18 '@evan/bacon', 19 '--yarn', 20 'another@foobar', 21 'file:../thing', 22 '--', 23 '--npm', 24 '-g', 25 'not-a-plugin', 26 ]); 27 expect(result).toEqual({ 28 variadic: ['bacon', '@evan/bacon', 'another@foobar', 'file:../thing'], 29 options: { 30 npm: false, 31 yarn: true, 32 check: false, 33 pnpm: false, 34 fix: false, 35 }, 36 extras: ['--npm', '-g', 'not-a-plugin'], 37 }); 38 }); 39 it(`allows known values without correct chaining`, async () => { 40 const result = await resolveArgsAsync(['expo', '--npm', '--check', '--']); 41 expect(result).toEqual({ 42 variadic: ['expo'], 43 options: { 44 npm: true, 45 yarn: false, 46 check: true, 47 pnpm: false, 48 fix: false, 49 }, 50 extras: [], 51 }); 52 }); 53}); 54