-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(typescript-estree): add unit tests for inferSingleRun function (#…
…8943) test: add testCase
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
packages/typescript-estree/tests/lib/inferSingleRun.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import * as path from 'path'; | ||
|
||
import { inferSingleRun } from '../../src/parseSettings/inferSingleRun'; | ||
|
||
describe('inferSingleRun', () => { | ||
const originalEnvCI = process.env.CI; | ||
const originalProcessArgv = process.argv; | ||
const originalTSESTreeSingleRun = process.env.TSESTREE_SINGLE_RUN; | ||
|
||
afterEach(() => { | ||
process.env.CI = originalEnvCI; | ||
process.argv = originalProcessArgv; | ||
process.env.TSESTREE_SINGLE_RUN = originalTSESTreeSingleRun; | ||
}); | ||
|
||
it.each(['project', 'programs'])( | ||
'returns false when given %j is null', | ||
key => { | ||
const actual = inferSingleRun({ [key]: null }); | ||
|
||
expect(actual).toBe(false); | ||
}, | ||
); | ||
|
||
it.each([ | ||
['true', true], | ||
['false', false], | ||
])('return %s when given TSESTREE_SINGLE_RUN is "%s"', (run, expected) => { | ||
process.env.TSESTREE_SINGLE_RUN = run; | ||
|
||
const actual = inferSingleRun({ | ||
programs: null, | ||
project: './tsconfig.json', | ||
}); | ||
|
||
expect(actual).toBe(expected); | ||
}); | ||
|
||
it.each(['node_modules/.bin/eslint', 'node_modules/eslint/bin/eslint.js'])( | ||
'returns true when singleRun is inferred from process.argv', | ||
pathName => { | ||
process.argv = ['', path.normalize(pathName), '']; | ||
|
||
const actual = inferSingleRun({ | ||
programs: null, | ||
project: './tsconfig.json', | ||
allowAutomaticSingleRunInference: true, | ||
}); | ||
|
||
expect(actual).toBe(true); | ||
}, | ||
); | ||
|
||
it('returns true when singleRun is inferred from CI=true', () => { | ||
process.env.CI = 'true'; | ||
|
||
const actual = inferSingleRun({ | ||
programs: null, | ||
project: './tsconfig.json', | ||
allowAutomaticSingleRunInference: true, | ||
}); | ||
|
||
expect(actual).toBe(true); | ||
}); | ||
|
||
it('returns false when there is no way to infer singleRun', () => { | ||
const actual = inferSingleRun({ | ||
programs: null, | ||
project: './tsconfig.json', | ||
}); | ||
|
||
expect(actual).toBe(false); | ||
}); | ||
|
||
it('returns false even if CI=true when allowAutomaticSingleRunInference is not true', () => { | ||
process.env.CI = 'true'; | ||
|
||
const actual = inferSingleRun({ | ||
programs: null, | ||
project: './tsconfig.json', | ||
}); | ||
|
||
expect(actual).toBe(false); | ||
}); | ||
|
||
it.each(['node_modules/.bin/eslint', 'node_modules/eslint/bin/eslint.js'])( | ||
'returns false even if singleRun is inferred from process.argv when allowAutomaticSingleRunInference is not true', | ||
pathName => { | ||
process.argv = ['', path.normalize(pathName), '']; | ||
|
||
const actual = inferSingleRun({ | ||
programs: null, | ||
project: './tsconfig.json', | ||
}); | ||
|
||
expect(actual).toBe(false); | ||
}, | ||
); | ||
}); |