Skip to content
Permalink
Browse files

test(plugin-tslint): add missing test cases for plugin-tslint (#303)

  • Loading branch information...
armano2 committed Feb 23, 2019
1 parent 4de9305 commit b29cad91cdb3ee3f091af60a96d0c03ac84f1033
@@ -54,7 +54,10 @@
}
},
{
"files": ["packages/eslint-plugin/test/**/*.ts"],
"files": [
"packages/eslint-plugin/test/**/*.ts",
"packages/eslint-plugin-tslint/tests/**/*.spec.ts"
],
"rules": {
"eslint-plugin/no-identical-tests": "error"
}
@@ -13,7 +13,6 @@ export class CustomLinter extends TSLintLinter {
}

getSourceFile(fileName: string) {
const result = this.program.getSourceFile(fileName);
return result;
return this.program.getSourceFile(fileName);
}
}
@@ -83,7 +83,7 @@ export const rules = {
},
],
},
create: function(context: Rule.RuleContext) {
create(context: Rule.RuleContext) {
const fileName = context.getFilename();
const sourceCode = context.getSourceCode().text;
const parserServices: ParserServices | undefined = context.parserServices;
@@ -1,5 +1,5 @@
import { rules } from '../src/index';
import { RuleTester } from 'eslint';
import { rules } from '../src';
import { Linter, RuleTester } from 'eslint';
import { readFileSync } from 'fs';

const ruleTester = new RuleTester({
@@ -125,3 +125,58 @@ ruleTester.run('tslint/config', rules.config, {
},
],
});

describe('tslint/error', () => {
function testOutput(code: string, config: Linter.Config): void {
const linter = new Linter();
linter.defineRule('tslint/config', rules.config);

expect(() => linter.verify(code, config)).toThrow(
`You must provide a value for the "parserOptions.project" property for @typescript-eslint/parser`,
);
}

it('should error on missing project', () => {
testOutput('foo;', {
rules: {
'tslint/config': [2, tslintRulesConfig],
},
parser: '@typescript-eslint/parser',
});
});

it('should error on default parser', () => {
testOutput('foo;', {
parserOptions: {
project: `${__dirname}/test-project/tsconfig.json`,
},
rules: {
'tslint/config': [2, tslintRulesConfig],
},
});
});

it('should not crash if there is no tslint rules specified', () => {
const linter = new Linter();
jest.spyOn(console, 'warn').mockImplementation();
linter.defineRule('tslint/config', rules.config);
expect(() =>
linter.verify('foo;', {
parserOptions: {
project: `${__dirname}/test-project/tsconfig.json`,
},
rules: {
'tslint/config': [2, {}],
},
parser: '@typescript-eslint/parser',
}),
).not.toThrow();

expect(console.warn).toHaveBeenCalledWith(
expect.stringContaining(
'No valid rules have been specified for TypeScript files',
),
);
jest.resetAllMocks();
});
});

0 comments on commit b29cad9

Please sign in to comment.
You can’t perform that action at this time.