1import { parseVariadicArguments, resolveArgsAsync } from '../resolveOptions';
2
3describe(parseVariadicArguments, () => {
4  it(`parses complex`, () => {
5    expect(
6      parseVariadicArguments([
7        'bacon',
8        '@evan/bacon',
9        '--yarn',
10        '-g',
11        '@evan/bacon/foobar.js',
12        './avocado.js',
13        '--',
14        '--npm',
15      ])
16    ).toEqual({
17      variadic: ['bacon', '@evan/bacon', '@evan/bacon/foobar.js', './avocado.js'],
18      extras: ['--npm'],
19      flags: { '--yarn': true, '-g': true },
20    });
21  });
22  it(`parses too many extras`, () => {
23    expect(() => parseVariadicArguments(['avo', '--', '--npm', '--'])).toThrow(
24      /Unexpected multiple --/
25    );
26  });
27});
28
29describe(resolveArgsAsync, () => {
30  it(`asserts invalid flags`, async () => {
31    await expect(resolveArgsAsync(['-g', '--bacon'])).rejects.toThrow(/Unexpected: -g, --bacon/);
32  });
33  it(`prevents bad combos`, async () => {
34    await expect(resolveArgsAsync(['--npm', '--yarn'])).rejects.toThrow(
35      /Specify at most one of: --npm, --yarn/
36    );
37  });
38  it(`allows known values`, async () => {
39    const result = await resolveArgsAsync([
40      'bacon',
41      '@evan/bacon',
42      '--yarn',
43      'another@foobar',
44      'file:../thing',
45      '--',
46      '--npm',
47      '-g',
48      'not-a-plugin',
49    ]);
50    expect(result).toEqual({
51      variadic: ['bacon', '@evan/bacon', 'another@foobar', 'file:../thing'],
52      options: {
53        npm: false,
54        yarn: true,
55        check: false,
56        fix: false,
57      },
58      extras: ['--npm', '-g', 'not-a-plugin'],
59    });
60  });
61  it(`allows known values without correct chaining`, async () => {
62    const result = await resolveArgsAsync(['expo', '--npm', '--check', '--']);
63    expect(result).toEqual({
64      variadic: ['expo'],
65      options: {
66        npm: true,
67        yarn: false,
68        check: true,
69        fix: false,
70      },
71      extras: [],
72    });
73  });
74});
75