Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions packages/rstack/tests/cli/fmt/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ test('does not load Prettier config or ignore files', () => {
expect(readProjectFile('index.ts')).toBe('function getMessage() {\n return "hello";\n}\n');
});

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

const result = runFmt([
option,
'--ignore-path',
'.prettierignore',
`${option}=config/extra.ignore`,
'--ignore-path=config/extra.ignore',
'src/ignored-by-root.ts',
'src/ignored-by-extra.ts',
'src/index.ts',
Expand Down Expand Up @@ -437,14 +437,6 @@ test('formats stdin for the given filepath', () => {
expect(result.stderr).toBe('');
});

test('formats stdin with the camel-case option', () => {
const result = runFmtStdin(['--stdinFilepath', 'data.json'], '{"a":1,"b":[2,3]}');

expect(result.status).toBe(0);
expect(result.stdout).toBe('{ "a": 1, "b": [2, 3] }\n');
expect(result.stderr).toBe('');
});

test('applies define.fmt options and overrides to stdin', () => {
writeProjectFile(
'rstack.config.ts',
Expand Down Expand Up @@ -598,18 +590,15 @@ test('returns exit code 2 when no files match', () => {
}
});

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

expect(result.status).toBe(0);
expect(result.stdout).toBe('');
expect(result.stderr).toBe('');
}
},
);
expect(result.status).toBe(0);
expect(result.stdout).toBe('');
expect(result.stderr).toBe('');
}
});

test('counts only supported files', () => {
writeProjectFile('index.ts', 'const value = 1;\n');
Expand Down
6 changes: 3 additions & 3 deletions packages/rstack/tests/cli/staged/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ test('should pass long options to lint-staged', async ({ expect }) => {
});
});

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

expect(mocks.lintStaged).toHaveBeenCalledWith({
allowEmpty: true,
allowEmpty: undefined,
concurrent: 1,
config: stagedConfig,
cwd: undefined,
Expand Down
56 changes: 19 additions & 37 deletions packages/rstack/tests/fmt/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ test.each([
['--write', 'write'],
['--check', 'check'],
['--list-different', 'list-different'],
['--listDifferent', 'list-different'],
] as const)('parses %s mode', (option, mode) => {
expect(parseFmtCLIArgs([option])).toEqual({
mode,
Expand All @@ -44,19 +43,16 @@ test.each([
});
});

test.each(['--parallel-workers', '--parallelWorkers'])(
'configures parallel worker count with %s',
(option) => {
expect(parseFmtCLIArgs([option, '3'])).toEqual({
mode: 'write',
patterns: [],
ignorePaths: [],
noErrorOnUnmatchedPattern: false,
maxWorkers: 3,
help: false,
});
},
);
test('configures parallel worker count', () => {
expect(parseFmtCLIArgs(['--parallel-workers', '3'])).toEqual({
mode: 'write',
patterns: [],
ignorePaths: [],
noErrorOnUnmatchedPattern: false,
maxWorkers: 3,
help: false,
});
});

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

test('prefers the kebab-case parallel worker option', () => {
expect(parseFmtCLIArgs(['--parallel-workers', '2', '--parallelWorkers', '3']).maxWorkers).toBe(2);
});

test('preserves file paths and globs', () => {
const patterns = ['src/file with spaces.ts', 'src/**/*.{js,ts}', '!src/generated/**'];

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

test.each(['--ignore-path', '--ignorePath'])('collects repeated ignore paths with %s', (option) => {
expect(
parseFmtCLIArgs([option, '.prettierignore', `${option}=config/format.ignore`]).ignorePaths,
).toEqual(['.prettierignore', 'config/format.ignore']);
});

test('combines kebab-case and camel-case ignore paths', () => {
test('collects repeated ignore paths', () => {
expect(
parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignorePath', 'config/format.ignore'])
parseFmtCLIArgs(['--ignore-path', '.prettierignore', '--ignore-path=config/format.ignore'])
.ignorePaths,
).toEqual(['.prettierignore', 'config/format.ignore']);
});

test.each(['--no-error-on-unmatched-pattern', '--noErrorOnUnmatchedPattern'])(
'parses %s',
(option) => {
expect(parseFmtCLIArgs([option]).noErrorOnUnmatchedPattern).toBe(true);
},
);
test('parses --no-error-on-unmatched-pattern', () => {
expect(parseFmtCLIArgs(['--no-error-on-unmatched-pattern']).noErrorOnUnmatchedPattern).toBe(true);
});

test.each(['--stdin-filepath', '--stdinFilepath'])('parses %s', (option) => {
expect(parseFmtCLIArgs([option, 'src/index.ts'])).toEqual({
test('parses --stdin-filepath', () => {
expect(parseFmtCLIArgs(['--stdin-filepath', 'src/index.ts'])).toEqual({
mode: 'write',
patterns: [],
ignorePaths: [],
Expand All @@ -143,7 +126,7 @@ test('accepts a worker count with --stdin-filepath', () => {
});
});

test.each(['--write', '--check', '--list-different', '--listDifferent'])(
test.each(['--write', '--check', '--list-different'])(
'rejects %s with --stdin-filepath',
(option) => {
expect(() => parseFmtCLIArgs(['--stdin-filepath', 'index.ts', option])).toThrow(
Expand All @@ -168,7 +151,6 @@ test('provides command help', () => {
test.each([
['--write', '--check'],
['--write', '--list-different'],
['--write', '--listDifferent'],
['--check', '--list-different'],
['--write', '--check', '--list-different'],
])('rejects conflicting modes: %s', (...args) => {
Expand All @@ -177,7 +159,7 @@ test.each([
);
});

test.each(['--unknown', '--no-cache', '--no-parallel', '--noParallel'])(
test.each(['--unknown', '--no-cache', '--no-parallel'])(
'rejects unsupported option %s',
(option) => {
expect(() => parseFmtCLIArgs([option])).toThrow();
Expand Down