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      },
56      extras: ['--npm', '-g', 'not-a-plugin'],
57    });
58  });
59  it(`allows known values without correct chaining`, async () => {
60    const result = await resolveArgsAsync(['expo', '--npm', '--']);
61    expect(result).toEqual({
62      variadic: ['expo'],
63      options: {
64        npm: true,
65        yarn: false,
66      },
67      extras: [],
68    });
69  });
70});
71