Skip to content

Commit 043c4b6

Browse files
committed
test(cli): simplify option alias coverage
1 parent a278f6a commit 043c4b6

3 files changed

Lines changed: 33 additions & 62 deletions

File tree

‎packages/rstack/tests/cli/fmt/index.test.ts‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ test('does not load Prettier config or ignore files', () => {
195195
expect(readProjectFile('index.ts')).toBe('function getMessage() {\n return "hello";\n}\n');
196196
});
197197

198-
test.each(['--ignore-path', '--ignorePath'])('applies repeated ignore paths with %s', (option) => {
198+
test('applies repeated ignore paths', () => {
199199
writeProjectFile('.prettierignore', 'src/ignored-by-root.ts\n');
200200
writeProjectFile('config/extra.ignore', '../src/ignored-by-extra.ts\n');
201201
writeProjectFile('src/ignored-by-root.ts', 'const root="ignored"');
202202
writeProjectFile('src/ignored-by-extra.ts', 'const extra="ignored"');
203203
writeProjectFile('src/index.ts', 'const index="formatted"');
204204

205205
const result = runFmt([
206-
option,
206+
'--ignore-path',
207207
'.prettierignore',
208-
`${option}=config/extra.ignore`,
208+
'--ignore-path=config/extra.ignore',
209209
'src/ignored-by-root.ts',
210210
'src/ignored-by-extra.ts',
211211
'src/index.ts',
@@ -437,14 +437,6 @@ test('formats stdin for the given filepath', () => {
437437
expect(result.stderr).toBe('');
438438
});
439439

440-
test('formats stdin with the camel-case option', () => {
441-
const result = runFmtStdin(['--stdinFilepath', 'data.json'], '{"a":1,"b":[2,3]}');
442-
443-
expect(result.status).toBe(0);
444-
expect(result.stdout).toBe('{ "a": 1, "b": [2, 3] }\n');
445-
expect(result.stderr).toBe('');
446-
});
447-
448440
test('applies define.fmt options and overrides to stdin', () => {
449441
writeProjectFile(
450442
'rstack.config.ts',
@@ -598,18 +590,15 @@ test('returns exit code 2 when no files match', () => {
598590
}
599591
});
600592

601-
test.each(['--no-error-on-unmatched-pattern', '--noErrorOnUnmatchedPattern'])(
602-
'allows no files to match with %s',
603-
(option) => {
604-
for (const modeArgs of [[], ['--check'], ['--list-different']]) {
605-
const result = runFmt([...modeArgs, option, 'missing/**/*.ts']);
593+
test('allows no files to match with --no-error-on-unmatched-pattern', () => {
594+
for (const modeArgs of [[], ['--check'], ['--list-different']]) {
595+
const result = runFmt([...modeArgs, '--no-error-on-unmatched-pattern', 'missing/**/*.ts']);
606596

607-
expect(result.status).toBe(0);
608-
expect(result.stdout).toBe('');
609-
expect(result.stderr).toBe('');
610-
}
611-
},
612-
);
597+
expect(result.status).toBe(0);
598+
expect(result.stdout).toBe('');
599+
expect(result.stderr).toBe('');
600+
}
601+
});
613602

614603
test('counts only supported files', () => {
615604
writeProjectFile('index.ts', 'const value = 1;\n');

‎packages/rstack/tests/cli/staged/index.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ test('should pass long options to lint-staged', async ({ expect }) => {
8989
});
9090
});
9191

92-
test('should pass short options and aliases to lint-staged', async ({ expect }) => {
93-
await runStagedCLI(['--allowEmpty', '-p', '1', '-d', '-q', '-r', '-v']);
92+
test('should pass short options to lint-staged', async ({ expect }) => {
93+
await runStagedCLI(['-p', '1', '-d', '-q', '-r', '-v']);
9494

9595
expect(mocks.lintStaged).toHaveBeenCalledWith({
96-
allowEmpty: true,
96+
allowEmpty: undefined,
9797
concurrent: 1,
9898
config: stagedConfig,
9999
cwd: undefined,

‎packages/rstack/tests/fmt/cli.test.ts‎

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ test.each([
3232
['--write', 'write'],
3333
['--check', 'check'],
3434
['--list-different', 'list-different'],
35-
['--listDifferent', 'list-different'],
3635
] as const)('parses %s mode', (option, mode) => {
3736
expect(parseFmtCLIArgs([option])).toEqual({
3837
mode,
@@ -44,19 +43,16 @@ test.each([
4443
});
4544
});
4645

47-
test.each(['--parallel-workers', '--parallelWorkers'])(
48-
'configures parallel worker count with %s',
49-
(option) => {
50-
expect(parseFmtCLIArgs([option, '3'])).toEqual({
51-
mode: 'write',
52-
patterns: [],
53-
ignorePaths: [],
54-
noErrorOnUnmatchedPattern: false,
55-
maxWorkers: 3,
56-
help: false,
57-
});
58-
},
59-
);
46+
test('configures parallel worker count', () => {
47+
expect(parseFmtCLIArgs(['--parallel-workers', '3'])).toEqual({
48+
mode: 'write',
49+
patterns: [],
50+
ignorePaths: [],
51+
noErrorOnUnmatchedPattern: false,
52+
maxWorkers: 3,
53+
help: false,
54+
});
55+
});
6056

6157
test.each(['0', '-1', '1.5', 'invalid', '9007199254740992'])(
6258
'rejects invalid parallel worker count %s',
@@ -67,10 +63,6 @@ test.each(['0', '-1', '1.5', 'invalid', '9007199254740992'])(
6763
},
6864
);
6965

70-
test('prefers the kebab-case parallel worker option', () => {
71-
expect(parseFmtCLIArgs(['--parallel-workers', '2', '--parallelWorkers', '3']).maxWorkers).toBe(2);
72-
});
73-
7466
test('preserves file paths and globs', () => {
7567
const patterns = ['src/file with spaces.ts', 'src/**/*.{js,ts}', '!src/generated/**'];
7668

@@ -99,28 +91,19 @@ test.each(['--help', '-h'])('parses %s', (option) => {
9991
expect(parseFmtCLIArgs([option]).help).toBe(true);
10092
});
10193

102-
test.each(['--ignore-path', '--ignorePath'])('collects repeated ignore paths with %s', (option) => {
103-
expect(
104-
parseFmtCLIArgs([option, '.prettierignore', `${option}=config/format.ignore`]).ignorePaths,
105-
).toEqual(['.prettierignore', 'config/format.ignore']);
106-
});
107-
108-
test('combines kebab-case and camel-case ignore paths', () => {
94+
test('collects repeated ignore paths', () => {
10995
expect(
110-
parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignorePath', 'config/format.ignore'])
96+
parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignore-path=config/format.ignore'])
11197
.ignorePaths,
11298
).toEqual(['.prettierignore', 'config/format.ignore']);
11399
});
114100

115-
test.each(['--no-error-on-unmatched-pattern', '--noErrorOnUnmatchedPattern'])(
116-
'parses %s',
117-
(option) => {
118-
expect(parseFmtCLIArgs([option]).noErrorOnUnmatchedPattern).toBe(true);
119-
},
120-
);
101+
test('parses --no-error-on-unmatched-pattern', () => {
102+
expect(parseFmtCLIArgs(['--no-error-on-unmatched-pattern']).noErrorOnUnmatchedPattern).toBe(true);
103+
});
121104

122-
test.each(['--stdin-filepath', '--stdinFilepath'])('parses %s', (option) => {
123-
expect(parseFmtCLIArgs([option, 'src/index.ts'])).toEqual({
105+
test('parses --stdin-filepath', () => {
106+
expect(parseFmtCLIArgs(['--stdin-filepath', 'src/index.ts'])).toEqual({
124107
mode: 'write',
125108
patterns: [],
126109
ignorePaths: [],
@@ -143,7 +126,7 @@ test('accepts a worker count with --stdin-filepath', () => {
143126
});
144127
});
145128

146-
test.each(['--write', '--check', '--list-different', '--listDifferent'])(
129+
test.each(['--write', '--check', '--list-different'])(
147130
'rejects %s with --stdin-filepath',
148131
(option) => {
149132
expect(() => parseFmtCLIArgs(['--stdin-filepath', 'index.ts', option])).toThrow(
@@ -168,7 +151,6 @@ test('provides command help', () => {
168151
test.each([
169152
['--write', '--check'],
170153
['--write', '--list-different'],
171-
['--write', '--listDifferent'],
172154
['--check', '--list-different'],
173155
['--write', '--check', '--list-different'],
174156
])('rejects conflicting modes: %s', (...args) => {
@@ -177,7 +159,7 @@ test.each([
177159
);
178160
});
179161

180-
test.each(['--unknown', '--no-cache', '--no-parallel', '--noParallel'])(
162+
test.each(['--unknown', '--no-cache', '--no-parallel'])(
181163
'rejects unsupported option %s',
182164
(option) => {
183165
expect(() => parseFmtCLIArgs([option])).toThrow();

0 commit comments

Comments
 (0)