Skip to content

Commit 84df1d6

Browse files
G-RathSimenB
authored andcommitted
chore(util): simplify check for test names (#317)
1 parent 7ae98f5 commit 84df1d6

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

src/rules/no-if.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { getDocsUrl, getNodeName, isTestCase, testCaseNames } from './util';
1+
import { getDocsUrl, isTestCase } from './util';
22

33
const isTestArrowFunction = node =>
44
node !== undefined &&
55
node.type === 'ArrowFunctionExpression' &&
6-
node.parent.type === 'CallExpression' &&
7-
testCaseNames.has(getNodeName(node.parent.callee));
6+
isTestCase(node.parent);
87

98
export default {
109
meta: {

src/rules/util.js

+13-21
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,9 @@ export const argument = node =>
9797
export const argument2 = node =>
9898
node.parent.parent.parent.arguments && node.parent.parent.parent.arguments[0];
9999

100-
const describeAliases = new Set([
101-
'describe',
102-
'describe.only',
103-
'describe.skip',
104-
'fdescribe',
105-
'xdescribe',
106-
]);
100+
const describeAliases = new Set(['describe', 'fdescribe', 'xdescribe']);
107101

108-
export const testCaseNames = new Set([
109-
'fit',
110-
'it',
111-
'it.only',
112-
'it.skip',
113-
'test',
114-
'test.only',
115-
'test.skip',
116-
'xit',
117-
'xtest',
118-
]);
102+
const testCaseNames = new Set(['fit', 'it', 'test', 'xit', 'xtest']);
119103

120104
const testHookNames = new Set([
121105
'beforeAll',
@@ -147,17 +131,25 @@ export const getNodeName = node => {
147131
export const isHook = node =>
148132
node &&
149133
node.type === 'CallExpression' &&
150-
testHookNames.has(getNodeName(node.callee));
134+
node.callee.type === 'Identifier' &&
135+
testHookNames.has(node.callee.name);
151136

152137
export const isTestCase = node =>
153138
node &&
154139
node.type === 'CallExpression' &&
155-
testCaseNames.has(getNodeName(node.callee));
140+
((node.callee.type === 'Identifier' && testCaseNames.has(node.callee.name)) ||
141+
(node.callee.type === 'MemberExpression' &&
142+
node.callee.object.type === 'Identifier' &&
143+
testCaseNames.has(node.callee.object.name)));
156144

157145
export const isDescribe = node =>
158146
node &&
159147
node.type === 'CallExpression' &&
160-
describeAliases.has(getNodeName(node.callee));
148+
((node.callee.type === 'Identifier' &&
149+
describeAliases.has(node.callee.name)) ||
150+
(node.callee.type === 'MemberExpression' &&
151+
node.callee.object.type === 'Identifier' &&
152+
describeAliases.has(node.callee.object.name)));
161153

162154
export const isFunction = node =>
163155
node &&

0 commit comments

Comments
 (0)