Skip to content

test(typescript-estree): add unit tests for inferSingleRun function #8710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions packages/typescript-estree/tests/lib/inferSingleRun.test.ts
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);
},
);
});