-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess-exit-as-throw.ts
49 lines (38 loc) · 1.78 KB
/
process-exit-as-throw.ts
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
import assert from 'assert';
import { TSESLint } from '@typescript-eslint/utils';
import rule, { supported } from '../../../src/rules/process-exit-as-throw';
describe('process-exit-as-throw', () => {
let linter: TSESLint.Linter;
beforeEach(() => {
linter = new TSESLint.Linter();
linter.defineRule('process-exit-as-throw', rule);
});
(supported ? it : xit)("should get unreachable error after 'process.exit()'.", () => {
const code = ['foo();', 'process.exit(1);', 'bar();'].join('\n');
// eslint-disable-next-line @typescript-eslint/naming-convention
const messages = linter.verify(code, { rules: { 'no-unreachable': 'error', 'process-exit-as-throw': 'error' } });
assert.strictEqual(messages.length, 1);
assert.strictEqual(messages[0].message, 'Unreachable code.');
assert.strictEqual(messages[0].line, 3);
});
(supported ? it : xit)("should get no unreachable error after 'process.exit()' if this rule is turned off.", () => {
const code = ['foo();', 'process.exit(1);', 'bar();'].join('\n');
// eslint-disable-next-line @typescript-eslint/naming-convention
const messages = linter.verify(code, { rules: { 'no-unreachable': 'error', 'process-exit-as-throw': 'off' } });
assert.strictEqual(messages.length, 0);
});
(supported ? it : xit)("should get no consistent-return error after 'process.exit()'.", () => {
const code = [
'function foo() {',
' if (a) {',
' return 1;',
' } else {',
' process.exit(1);',
' }',
'}',
].join('\n');
// eslint-disable-next-line @typescript-eslint/naming-convention
const messages = linter.verify(code, { rules: { 'consistent-return': 'error', 'process-exit-as-throw': 'error' } });
assert.strictEqual(messages.length, 0);
});
});