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

adjust js guard behavior #317

Merged
merged 2 commits into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions src/rules/no-if.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,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',
]);
export const testCaseNames = new Set(['fit', 'it', 'test', 'xit', 'xtest']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to export this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to verify, test.only is still detected, yeah?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good point about the export - I'll check it right now.

Definitely still catches test.only, b/c otherwise no-focused-tests would fail :)

All of the places that actually do something specific for things like only & skip actually implement their own checks; which makes sense b/c there's no way to explicitly get them out of the Set.

That's why it all still works, b/c the sets & guards are meant to serve as a way to know if you're in the "jest domain" (and so if you should bother checking anything at all), rather than for explicit "is it this specific jest method".


const testHookNames = new Set([
'beforeAll',
Expand Down Expand Up @@ -127,17 +111,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