-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-parser.test.ts
More file actions
84 lines (74 loc) · 2.42 KB
/
Copy pathcli-parser.test.ts
File metadata and controls
84 lines (74 loc) · 2.42 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { describe, expect, it } from 'vitest';
import { createCommand } from '../cli/parser';
describe('CLI parser', () => {
it('should create command with expected metadata', () => {
const program = createCommand();
expect(program.name()).toBe('create-react-forge');
expect(program.description()).toContain('Production-ready React CLI scaffolder');
expect(program.version()).toMatch(/^\d+\.\d+\.\d+$/);
});
it('should register create command options with supported choices', () => {
const program = createCommand();
const createCmd = program.commands.find((cmd) => cmd.name() === 'create');
expect(createCmd).toBeDefined();
expect(createCmd?.description()).toBe('Create a new React project');
const stylingOption = createCmd?.options.find((o) => o.long === '--styling');
const stateOption = createCmd?.options.find((o) => o.long === '--state');
const runtimeOption = createCmd?.options.find((o) => o.long === '--runtime');
const unitRunnerOption = createCmd?.options.find((o) => o.long === '--unit-runner');
expect(runtimeOption?.argChoices).toEqual(['vite', 'nextjs']);
expect(stylingOption?.argChoices).toEqual([
'none',
'tailwind',
'styled-components',
'css-modules',
'css',
]);
expect(stateOption?.argChoices).toEqual(['none', 'redux', 'zustand', 'jotai']);
expect(unitRunnerOption?.argChoices).toEqual(['vitest', 'jest']);
});
it('should parse create command options', async () => {
const program = createCommand();
await program.parseAsync(
[
'node',
'create-react-forge',
'create',
'demo-app',
'--runtime',
'nextjs',
'--language',
'javascript',
'--styling',
'tailwind',
'--state',
'redux',
'--testing',
'unit-component',
'--unit-runner',
'jest',
'--e2e-runner',
'none',
'--pm',
'pnpm',
'--no-git',
'--no-query',
],
{ from: 'user' }
);
const createCmd = program.commands.find((cmd) => cmd.name() === 'create');
const parsed = createCmd?.opts();
expect(parsed).toMatchObject({
runtime: 'nextjs',
language: 'javascript',
styling: 'tailwind',
state: 'redux',
testing: 'unit-component',
unitRunner: 'jest',
e2eRunner: 'none',
pm: 'pnpm',
git: false,
query: false,
});
});
});