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, --pnpm, --yarn/
36    );
37    await expect(resolveArgsAsync(['--npm', '--pnpm', '--yarn'])).rejects.toThrow(
38      /Specify at most one of: --npm, --pnpm, --yarn/
39    );
40  });
41  it(`allows known values`, async () => {
42    const result = await resolveArgsAsync([
43      'bacon',
44      '@evan/bacon',
45      '--yarn',
46      'another@foobar',
47      'file:../thing',
48      '--',
49      '--npm',
50      '-g',
51      'not-a-plugin',
52    ]);
53    expect(result).toEqual({
54      variadic: ['bacon', '@evan/bacon', 'another@foobar', 'file:../thing'],
55      options: {
56        npm: false,
57        yarn: true,
58        check: false,
59        pnpm: false,
60        fix: false,
61      },
62      extras: ['--npm', '-g', 'not-a-plugin'],
63    });
64  });
65  it(`allows known values without correct chaining`, async () => {
66    const result = await resolveArgsAsync(['expo', '--npm', '--check', '--']);
67    expect(result).toEqual({
68      variadic: ['expo'],
69      options: {
70        npm: true,
71        yarn: false,
72        check: true,
73        pnpm: false,
74        fix: false,
75      },
76      extras: [],
77    });
78  });
79});
80