Skip to content

Commit

Permalink
feat(no-focused-tests): check each with table format (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Belco90 authored and G-Rath committed Nov 29, 2019
1 parent 22d890f commit fffcf9c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ test['only']('bar', () => {});
fdescribe('foo', () => {});
fit('foo', () => {});
ftest('bar', () => {});
fit.each`
table
`();
ftest.each`
table
`();
```

These patterns would not be considered warnings:
Expand All @@ -43,4 +49,12 @@ describe.skip('bar', () => {});
it.skip('bar', () => {});
test('foo', () => {});
test.skip('bar', () => {});
it.each()();
it.each`
table
`();
test.each()();
test.each`
table
`();
```
18 changes: 17 additions & 1 deletion src/rules/__tests__/no-focused-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../no-focused-tests';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new TSESLint.RuleTester({
parserOptions: {
ecmaVersion: 6,
},
});

ruleTester.run('no-focused-tests', rule, {
valid: [
Expand All @@ -13,6 +17,10 @@ ruleTester.run('no-focused-tests', rule, {
'test.skip()',
'var appliedOnly = describe.only; appliedOnly.apply(describe)',
'var calledOnly = it.only; calledOnly.call(it)',
'it.each()()',
'it.each`table`()',
'test.each()()',
'test.each`table`()',
],

invalid: [
Expand Down Expand Up @@ -64,5 +72,13 @@ ruleTester.run('no-focused-tests', rule, {
code: 'fit.each()',
errors: [{ messageId: 'focusedTest', column: 1, line: 1 }],
},
{
code: 'fit.each`table`()',
errors: [{ messageId: 'focusedTest', column: 1, line: 1 }],
},
{
code: 'ftest.each`table`()',
errors: [{ messageId: 'focusedTest', column: 1, line: 1 }],
},
],
});
10 changes: 10 additions & 0 deletions src/rules/no-focused-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export default createRule({
) {
context.report({ messageId: 'focusedTest', node: callee });
}

if (
callee.type === AST_NODE_TYPES.TaggedTemplateExpression &&
callee.tag.type === AST_NODE_TYPES.MemberExpression &&
callee.tag.object &&
callee.tag.object.type === AST_NODE_TYPES.Identifier &&
isCallToFocusedTestFunction(callee.tag.object)
) {
context.report({ messageId: 'focusedTest', node: callee });
}
},
}),
});

0 comments on commit fffcf9c

Please sign in to comment.