-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatterns.test.ts
More file actions
109 lines (87 loc) · 3.65 KB
/
Copy pathpatterns.test.ts
File metadata and controls
109 lines (87 loc) · 3.65 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { expect, test } from 'rstack/test';
import { normalizeDuration, setupFmtTest } from './helpers.ts';
const { projectFileExists, runFmt, writeProjectFile } = setupFmtTest();
test('returns exit code 2 when no files match', () => {
for (const modeArgs of [[], ['--check'], ['--list-different']]) {
const result = runFmt([...modeArgs, 'missing/**/*.ts']);
expect(result.status).toBe(2);
expect(result.stdout).toBe('');
expect(result.stderr).toContain(
'No supported files matched "missing/**/*.ts", or all matching files were ignored.',
);
expect(result.stderr).not.toContain('\n at ');
}
expect(projectFileExists('.rstack')).toBe(false);
});
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('');
}
});
test('counts only supported files', () => {
writeProjectFile('index.ts', 'const value = 1;\n');
writeProjectFile('notes.unknown', 'plain text');
const result = runFmt(['--check', 'index.ts', 'notes.unknown']);
expect(result.status).toBe(0);
expect(normalizeDuration(result.stdout)).toBe(
'start Checking formatting...\nsuccess Checked 1 file in <duration>. No issues found.\n',
);
expect(result.stderr).toBe('');
});
test('returns exit code 2 when all matched files are unsupported', () => {
writeProjectFile('notes.unknown', 'plain text');
for (const modeArgs of [[], ['--check'], ['--list-different']]) {
const result = runFmt([...modeArgs, 'notes.unknown']);
expect(result.status).toBe(2);
expect(result.stdout).not.toContain('success');
expect(result.stderr).toContain(
'No supported files matched "notes.unknown", or all matching files were ignored.',
);
expect(result.stderr).not.toContain('\n at ');
}
});
test('ignores unsupported files with --ignore-unknown', () => {
writeProjectFile('notes.unknown', 'plain text');
for (const modeArgs of [[], ['--check'], ['--list-different']]) {
const result = runFmt([...modeArgs, '--ignore-unknown', 'notes.unknown']);
expect(result.status).toBe(0);
const expectedStdout = modeArgs.includes('--check')
? 'start Checking formatting...\nsuccess No supported files to check.\n'
: modeArgs.includes('--list-different')
? ''
: 'start Formatting...\nsuccess No supported files to format.\n';
expect(result.stdout).toBe(expectedStdout);
expect(result.stderr).toBe('');
}
});
test('supports -u as an alias for --ignore-unknown', () => {
writeProjectFile('notes.unknown', 'plain text');
const result = runFmt(['-u', 'notes.unknown']);
expect(result.status).toBe(0);
expect(result.stdout).toBe(
'start Formatting...\nsuccess No supported files to format.\n',
);
expect(result.stderr).toBe('');
});
test('does not treat unmatched patterns as unknown files', () => {
const result = runFmt(['--ignore-unknown', 'missing/**/*.unknown']);
expect(result.status).toBe(2);
expect(result.stdout).toBe('');
expect(result.stderr).toContain(
'No supported files matched "missing/**/*.unknown"',
);
});
test('does not treat unsupported files as unmatched patterns', () => {
writeProjectFile('notes.unknown', 'plain text');
const result = runFmt(['--no-error-on-unmatched-pattern', 'notes.unknown']);
expect(result.status).toBe(2);
expect(result.stdout).toBe('start Formatting...\n');
expect(result.stderr).toContain('No supported files matched "notes.unknown"');
});