Skip to content

Commit

Permalink
fix(no-focused-tests): detect table format usage of .only.each
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Nov 30, 2019
1 parent ee23634 commit 0380bb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/rules/__tests__/no-focused-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ ruleTester.run('no-focused-tests', rule, {
code: 'describe.only.each()',
errors: [{ messageId: 'focusedTest', column: 10, line: 1 }],
},
{
code: 'describe.only.each`table`()',
errors: [{ messageId: 'focusedTest', column: 10, line: 1 }],
},
{
code: 'describe["only"]()',
errors: [{ messageId: 'focusedTest', column: 10, line: 1 }],
Expand All @@ -46,6 +50,10 @@ ruleTester.run('no-focused-tests', rule, {
code: 'it.only.each()',
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
},
{
code: 'it.only.each`table`()',
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
},
{
code: 'it["only"]()',
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
Expand All @@ -58,6 +66,10 @@ ruleTester.run('no-focused-tests', rule, {
code: 'test.only.each()',
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],
},
{
code: 'test.only.each`table`()',
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],
},
{
code: 'test["only"]()',
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],
Expand Down
15 changes: 4 additions & 11 deletions src/rules/no-focused-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export default createRule({
defaultOptions: [],
create: context => ({
CallExpression(node) {
const { callee } = node;
const callee =
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression
? node.callee.tag
: node.callee;

if (callee.type === AST_NODE_TYPES.MemberExpression) {
if (
Expand Down Expand Up @@ -78,16 +81,6 @@ 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 0380bb3

Please sign in to comment.