-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck.test.ts
More file actions
84 lines (67 loc) · 2.2 KB
/
Copy pathcheck.test.ts
File metadata and controls
84 lines (67 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
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 { expect, test } from 'rstack/test';
import { normalizeHelpOutput } from '#test-helpers';
import { setupFmtTest } from './fmt/helpers.ts';
const { runCLI, writeProjectFile } = setupFmtTest();
const runCheck = (args: string[] = []) => runCLI(['check', ...args]);
const writeLintConfig = (): void => {
writeProjectFile(
'rstack.config.ts',
`import { define } from "rstack";
define.lint([
{
files: ["**/*.{js,ts}"],
rules: { "no-debugger": "error" },
},
]);
`,
);
};
test('displays check help without loading config', () => {
writeProjectFile('rstack.config.ts', 'throw new Error("must not load");\n');
const result = runCheck(['--help']);
expect(normalizeHelpOutput(result.stdout)).toMatchSnapshot();
});
test('runs lint followed by a formatting check', () => {
writeLintConfig();
writeProjectFile('src/index.ts', 'const value=true');
const unformatted = runCheck();
expect(unformatted.status).toBe(1);
expect(unformatted.stdout).toContain('Checking formatting...');
expect(unformatted.stderr).toContain('Formatting issues found in 1 file.');
writeProjectFile('src/index.ts', 'const value = true;\n');
const formatted = runCheck();
expect(formatted.status).toBe(0);
expect(formatted.stdout).toContain('No issues found.');
expect(formatted.stderr).toBe('');
});
test('enables type checking only with --type-check', () => {
writeLintConfig();
writeProjectFile(
'tsconfig.json',
`{
"compilerOptions": {
"strict": true
},
"include": ["src"]
}
`,
);
writeProjectFile('src/index.ts', 'const value: string = 1;\n');
const withoutTypeCheck = runCheck();
const withTypeCheck = runCheck(['--type-check']);
expect(withoutTypeCheck.status).toBe(0);
expect(withTypeCheck.status).toBe(1);
expect(`${withTypeCheck.stdout}\n${withTypeCheck.stderr}`).toContain(
'TS2322',
);
});
test('does not run the formatting check when lint fails', () => {
writeLintConfig();
writeProjectFile('src/index.js', 'debugger;\n');
const result = runCheck();
expect(result.status).toBe(1);
expect(`${result.stdout}\n${result.stderr}`).toContain(
"Unexpected 'debugger' statement",
);
expect(result.stdout).not.toContain('Checking formatting...');
});