Skip to content

Commit

Permalink
chore(util): simplify check for test names (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored and SimenB committed Jul 20, 2019
1 parent 7ae98f5 commit 84df1d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
5 changes: 2 additions & 3 deletions src/rules/no-if.js
@@ -1,10 +1,9 @@
import { getDocsUrl, getNodeName, isTestCase, testCaseNames } from './util';
import { getDocsUrl, isTestCase } from './util';

const isTestArrowFunction = node =>
node !== undefined &&
node.type === 'ArrowFunctionExpression' &&
node.parent.type === 'CallExpression' &&
testCaseNames.has(getNodeName(node.parent.callee));
isTestCase(node.parent);

export default {
meta: {
Expand Down
34 changes: 13 additions & 21 deletions src/rules/util.js
Expand Up @@ -97,25 +97,9 @@ export const argument = node =>
export const argument2 = node =>
node.parent.parent.parent.arguments && node.parent.parent.parent.arguments[0];

const describeAliases = new Set([
'describe',
'describe.only',
'describe.skip',
'fdescribe',
'xdescribe',
]);
const describeAliases = new Set(['describe', 'fdescribe', 'xdescribe']);

export const testCaseNames = new Set([
'fit',
'it',
'it.only',
'it.skip',
'test',
'test.only',
'test.skip',
'xit',
'xtest',
]);
const testCaseNames = new Set(['fit', 'it', 'test', 'xit', 'xtest']);

const testHookNames = new Set([
'beforeAll',
Expand Down Expand Up @@ -147,17 +131,25 @@ export const getNodeName = node => {
export const isHook = node =>
node &&
node.type === 'CallExpression' &&
testHookNames.has(getNodeName(node.callee));
node.callee.type === 'Identifier' &&
testHookNames.has(node.callee.name);

export const isTestCase = node =>
node &&
node.type === 'CallExpression' &&
testCaseNames.has(getNodeName(node.callee));
((node.callee.type === 'Identifier' && testCaseNames.has(node.callee.name)) ||
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
testCaseNames.has(node.callee.object.name)));

export const isDescribe = node =>
node &&
node.type === 'CallExpression' &&
describeAliases.has(getNodeName(node.callee));
((node.callee.type === 'Identifier' &&
describeAliases.has(node.callee.name)) ||
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
describeAliases.has(node.callee.object.name)));

export const isFunction = node =>
node &&
Expand Down

0 comments on commit 84df1d6

Please sign in to comment.