Skip to content
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

feat(no-focused-tests): check focused tests using .each with table format #430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
`();
```
18 changes: 17 additions & 1 deletion src/rules/__tests__/no-focused-tests.test.ts
@@ -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
Expand Up @@ -84,6 +84,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 });
}
},
}),
});