-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcli.test.ts
More file actions
58 lines (56 loc) · 2.2 KB
/
cli.test.ts
File metadata and controls
58 lines (56 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { resolve } from '@css-modules-kit/core';
import { describe, expect, it } from 'vitest';
import { parseCLIArgs } from './cli.js';
import { ParseCLIArgsError } from './error.js';
const cwd = '/app';
describe('parseCLIArgs', () => {
it('should return default values when no options are provided', () => {
const args = parseCLIArgs([], cwd);
expect(args).toStrictEqual({
help: false,
version: false,
project: resolve(cwd),
pretty: undefined,
clean: false,
watch: false,
preserveWatchOutput: false,
});
});
it('should parse --help option', () => {
expect(parseCLIArgs(['--help'], cwd).help).toBe(true);
});
it('should parse --version option', () => {
expect(parseCLIArgs(['--version'], cwd).version).toBe(true);
});
describe('should parse --project option', () => {
it.each([
[['--project', 'tsconfig.json'], resolve(cwd, 'tsconfig.json')],
[['--project', 'tsconfig.base.json'], resolve(cwd, 'tsconfig.base.json')],
[['--project', '.'], resolve(cwd)],
[['--project', 'src'], resolve(cwd, 'src')],
])('%s %s', (argv, expected) => {
const args = parseCLIArgs(argv, cwd);
expect(args.project).toStrictEqual(expected);
});
});
it('should parse --pretty option', () => {
expect(parseCLIArgs(['--pretty'], cwd).pretty).toBe(true);
expect(parseCLIArgs(['--no-pretty'], cwd).pretty).toBe(false);
});
it('should parse --clean option', () => {
expect(parseCLIArgs(['--clean'], cwd).clean).toBe(true);
expect(parseCLIArgs(['--no-clean'], cwd).clean).toBe(false);
});
it('should parse --watch option', () => {
expect(parseCLIArgs(['--watch'], cwd).watch).toBe(true);
expect(parseCLIArgs(['--no-watch'], cwd).watch).toBe(false);
expect(parseCLIArgs(['-w'], cwd).watch).toBe(true);
});
it('should parse --preserveWatchOutput option', () => {
expect(parseCLIArgs(['--preserveWatchOutput'], cwd).preserveWatchOutput).toBe(true);
expect(parseCLIArgs(['--no-preserveWatchOutput'], cwd).preserveWatchOutput).toBe(false);
});
it('should throw ParseCLIArgsError for invalid options', () => {
expect(() => parseCLIArgs(['--invalid-option'], cwd)).toThrow(ParseCLIArgsError);
});
});