|
| 1 | +import { join } from 'node:path'; |
1 | 2 | import { describe, expect } from 'vitest';
|
2 | 3 | import { CoreConfig } from '@code-pushup/models';
|
3 | 4 | import { objectToCliArgs } from '@code-pushup/utils';
|
4 | 5 | import { yargsCli } from '../yargs-cli';
|
5 | 6 | import { yargsCoreConfigOptionsDefinition } from './core-config-options';
|
6 | 7 |
|
7 | 8 | describe('configOptions', () => {
|
8 |
| - function cli(args: Record<string, unknown>): Promise<CoreConfig> { |
9 |
| - return yargsCli(objectToCliArgs(args), { |
10 |
| - options: yargsCoreConfigOptionsDefinition(), |
11 |
| - }).parseAsync() as unknown as Promise<CoreConfig>; |
| 9 | + function argsFromCli(args: Record<string, unknown>): Promise<CoreConfig> { |
| 10 | + return yargsCli( |
| 11 | + objectToCliArgs({ |
| 12 | + ...args, |
| 13 | + config: join('code-pushup.config.ts'), |
| 14 | + }), |
| 15 | + { |
| 16 | + options: yargsCoreConfigOptionsDefinition(), |
| 17 | + }, |
| 18 | + ).parseAsync() as unknown as Promise<CoreConfig>; |
12 | 19 | }
|
13 | 20 |
|
14 | 21 | it('should fill defaults', async () => {
|
15 |
| - const config = await cli({}); |
| 22 | + const config = await argsFromCli({ config: 'code-pushup.config.ts' }); |
16 | 23 | expect(config).toBeDefined();
|
17 | 24 | // only _ and $0
|
18 |
| - expect(Object.keys(config)).toHaveLength(2); |
| 25 | + expect(Object.keys(config)).toHaveLength(3); |
19 | 26 | });
|
| 27 | + |
| 28 | + it.each([ |
| 29 | + // defaults |
| 30 | + [{}, {}], |
| 31 | + // persist.outputDir |
| 32 | + [{ 'persist.outputDir': 'my-dir' }, { outputDir: 'my-dir' }], |
| 33 | + // persist.filename |
| 34 | + [{ 'persist.filename': 'my-report' }, { filename: 'my-report' }], |
| 35 | + // persist.format |
| 36 | + [{ 'persist.format': 'md' }, { format: ['md'] }], |
| 37 | + [{ 'persist.format': ['md', 'json'] }, { format: ['md', 'json'] }], |
| 38 | + // [{ 'persist.format': 'md,json' }, { format: ['md', 'json'] }], @TODO comment in when config auto-loading is implemented |
| 39 | + ])( |
| 40 | + 'should parse persist options %j correctly as %j', |
| 41 | + async (options, result) => { |
| 42 | + const args = await argsFromCli(options); |
| 43 | + |
| 44 | + expect(args?.persist).toEqual(expect.objectContaining(result)); |
| 45 | + }, |
| 46 | + ); |
20 | 47 | });
|
0 commit comments