Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Add separate tsconfig.eslint.json for tests
Browse files Browse the repository at this point in the history
typescript-eslint fails when parsing files are not included within the
provided tsconfig.

See https://github.com/typescript-eslint/typescript-eslint/releases/tag/v2.0.0
  • Loading branch information
nickelc committed Dec 25, 2019
1 parent 949cd9e commit 71e0ed5
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
"project": "./tsconfig.eslint.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
Expand Down
69 changes: 69 additions & 0 deletions __tests__/input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { getInput, getInputBool, getInputList } from '../src/input';

describe('input', () => {
describe('getInput', () => {
it('env.INPUT_FOO | getInput("foo")', () => {
process.env['INPUT_FOO'] = '12345';
expect(getInput('foo')).toBe('12345');
});

it('env.INPUT_FOO-BAR | getInput("foo-bar")', () => {
process.env['INPUT_FOO-BAR'] = '12345';
expect(getInput('foo-bar')).toBe('12345');
});

it('env.INPUT_FOO_BAR | getInput("foo-bar")', () => {
process.env['INPUT_FOO_BAR'] = '12345';
expect(getInput('foo-bar')).toBe('12345');
});
});

describe('getInputBool', () => {
it('"true" == true', () => {
process.env['INPUT_VALUE'] = 'true';
expect(getInputBool('value')).toBe(true);
});

it('"1" == true', () => {
process.env['INPUT_VALUE'] = '1';
expect(getInputBool('value')).toBe(true);
});

it('"" == false', () => {
process.env['INPUT_VALUE'] = '';
expect(getInputBool('value')).toBe(false);
});

it('"foobar" == false', () => {
process.env['INPUT_VALUE'] = 'foobar';
expect(getInputBool('value')).toBe(false);
});
});

describe('getInputList', () => {
it('empty', () => {
process.env['INPUT_VALUE'] = '';
expect(getInputList('value')).toStrictEqual([]);
});
it('", ,, "', () => {
process.env['INPUT_VALUE'] = ', ,, ';
expect(getInputList('value')).toStrictEqual([]);
});
it('"one,two,three"', () => {
process.env['INPUT_VALUE'] = 'one,two,three';
expect(getInputList('value')).toStrictEqual([
'one',
'two',
'three',
]);
});
it('",one , two , three"', () => {
process.env['INPUT_VALUE'] = ',one , two , three';
expect(getInputList('value')).toStrictEqual([
'one',
'two',
'three',
]);
});
});
});
79 changes: 52 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
],
"scripts": {
"build": "tsc -p .",
"format": "prettier --write 'src/**/*.{js,ts,tsx}'",
"lint": "tsc --noEmit && eslint 'src/**/*.{js,ts,tsx}'",
"format": "prettier --write 'src/**/*.ts' '__tests__/**/*.ts'",
"lint": "tsc --noEmit && eslint 'src/**/*.ts' '__tests__/**/*.ts'",
"refresh": "rm -rf ./dist/* && npm run build",
"test": "jest --passWithNoTests",
"test": "jest -c jest.config.json",
"watch": "tsc -p . -w"
},
"repository": {
Expand Down Expand Up @@ -48,7 +48,7 @@
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"prettier": "^1.19.1",
"ts-node": "^8.5.4",
"ts-jest": "^24.2.0",
"typescript": "^3.7.2"
}
}
7 changes: 7 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"__tests__/**/*.ts"
]
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
"pretty": true,
"removeComments": true,
"resolveJsonModule": true,
"rootDir": "src",
"strict": true,
"suppressImplicitAnyIndexErrors": false,
"target": "es2018",
"declaration": true,
"sourceMap": true
},
"include": [
"src"
"src/**/*.ts"
]
}

0 comments on commit 71e0ed5

Please sign in to comment.