Skip to content

Commit 7984ef7

Browse files
authored
test(typescript-estree): add unit tests for inferSingleRun function (typescript-eslint#8943)
test: add testCase
1 parent 6e1241b commit 7984ef7

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import * as path from 'path';
2+
3+
import { inferSingleRun } from '../../src/parseSettings/inferSingleRun';
4+
5+
describe('inferSingleRun', () => {
6+
const originalEnvCI = process.env.CI;
7+
const originalProcessArgv = process.argv;
8+
const originalTSESTreeSingleRun = process.env.TSESTREE_SINGLE_RUN;
9+
10+
afterEach(() => {
11+
process.env.CI = originalEnvCI;
12+
process.argv = originalProcessArgv;
13+
process.env.TSESTREE_SINGLE_RUN = originalTSESTreeSingleRun;
14+
});
15+
16+
it.each(['project', 'programs'])(
17+
'returns false when given %j is null',
18+
key => {
19+
const actual = inferSingleRun({ [key]: null });
20+
21+
expect(actual).toBe(false);
22+
},
23+
);
24+
25+
it.each([
26+
['true', true],
27+
['false', false],
28+
])('return %s when given TSESTREE_SINGLE_RUN is "%s"', (run, expected) => {
29+
process.env.TSESTREE_SINGLE_RUN = run;
30+
31+
const actual = inferSingleRun({
32+
programs: null,
33+
project: './tsconfig.json',
34+
});
35+
36+
expect(actual).toBe(expected);
37+
});
38+
39+
it.each(['node_modules/.bin/eslint', 'node_modules/eslint/bin/eslint.js'])(
40+
'returns true when singleRun is inferred from process.argv',
41+
pathName => {
42+
process.argv = ['', path.normalize(pathName), ''];
43+
44+
const actual = inferSingleRun({
45+
programs: null,
46+
project: './tsconfig.json',
47+
allowAutomaticSingleRunInference: true,
48+
});
49+
50+
expect(actual).toBe(true);
51+
},
52+
);
53+
54+
it('returns true when singleRun is inferred from CI=true', () => {
55+
process.env.CI = 'true';
56+
57+
const actual = inferSingleRun({
58+
programs: null,
59+
project: './tsconfig.json',
60+
allowAutomaticSingleRunInference: true,
61+
});
62+
63+
expect(actual).toBe(true);
64+
});
65+
66+
it('returns false when there is no way to infer singleRun', () => {
67+
const actual = inferSingleRun({
68+
programs: null,
69+
project: './tsconfig.json',
70+
});
71+
72+
expect(actual).toBe(false);
73+
});
74+
75+
it('returns false even if CI=true when allowAutomaticSingleRunInference is not true', () => {
76+
process.env.CI = 'true';
77+
78+
const actual = inferSingleRun({
79+
programs: null,
80+
project: './tsconfig.json',
81+
});
82+
83+
expect(actual).toBe(false);
84+
});
85+
86+
it.each(['node_modules/.bin/eslint', 'node_modules/eslint/bin/eslint.js'])(
87+
'returns false even if singleRun is inferred from process.argv when allowAutomaticSingleRunInference is not true',
88+
pathName => {
89+
process.argv = ['', path.normalize(pathName), ''];
90+
91+
const actual = inferSingleRun({
92+
programs: null,
93+
project: './tsconfig.json',
94+
});
95+
96+
expect(actual).toBe(false);
97+
},
98+
);
99+
});

0 commit comments

Comments
 (0)