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 154c0b8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/rules/no-focused-tests.md
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
`();
```
20 changes: 19 additions & 1 deletion src/rules/__tests__/no-focused-tests.test.ts
@@ -1,7 +1,13 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';
import resolveFrom from 'resolve-from';
import rule from '../no-focused-tests';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new TSESLint.RuleTester({
parser: resolveFrom(require.resolve('eslint'), 'espree'),
parserOptions: {
ecmaVersion: 6,
},
});

ruleTester.run('no-focused-tests', rule, {
valid: [
Expand All @@ -13,6 +19,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 +74,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
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 154c0b8

Please sign in to comment.