-
Notifications
You must be signed in to change notification settings - Fork 240
feat(rules): add .concurrent support #498
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(rules): add .concurrent support #498
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
I've left details on how to remove all the type casts, which are my main blocker on merging this PR.
I also think isConcurrentExpression
can be improved, but am happy to do that myself as I need to break isTestCase
& friends up once this is merged anyway (both things you're welcome to attempt yourself, but don't feel you have to if you'd like to move on to other things 😄)
src/rules/no-focused-tests.ts
Outdated
isSupportedAccessor(callee.property, 'only'); | ||
isSupportedAccessor( | ||
isConcurrentExpression(callee) | ||
? (callee.parent as TSESTree.MemberExpression).property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast can be eliminated by making isConcurrentExpression
a proper type guard.
src/rules/no-focused-tests.ts
Outdated
getNodeName(expression) && | ||
new RegExp( | ||
`(${validTestCaseNames.join('|')})\.${TestCaseProperty.concurrent}`, | ||
).test(getNodeName(expression) as string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast can be eliminated by assigning the result of getNodeName
to a variable, and then checking that variable, instead of calling getNodeName
twice.
src/rules/no-focused-tests.ts
Outdated
]); | ||
|
||
const isConcurrentExpression = (expression: TSESTree.Node) => | ||
getNodeName(expression) && | ||
new RegExp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of this, as it's hard to understand what the logic will be at runtime - instead, it would be better to use standard conditional checks against the AST structure, like we do with isDescribeEach
& co.
@@ -641,7 +658,8 @@ export const isTestCase = ( | |||
node.callee.object.type === AST_NODE_TYPES.Identifier && | |||
TestCaseName.hasOwnProperty(node.callee.object.name) && | |||
node.callee.property.type === AST_NODE_TYPES.Identifier && | |||
TestCaseProperty.hasOwnProperty(node.callee.property.name)) | |||
TestCaseProperty.hasOwnProperty(node.callee.property.name)) || | |||
isConcurrentTestCase(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to bring the checks required from isConcurrentTestCase
into here, to save on duplicating conditional checks as it should just be a matter of adding a third layer.
Once this PR is merged, I'm going to swing by this method to see about breaking it up a bit and making it more readable.
First of all, thanks for the review @G-Rath. I'll do the requested changes today or tomorrow. About the refactor i can try to do this, but in other PR to not block this one, if you get me some guidance ou even open an issue describing your ideias would be nice. But if you prefer to yourself do this refactor and not open an issue describing it, feel free. |
@leonardovillela No problem - The refactor definitely doesn't need to be done anytime soon, nor block. It's probably better at this point for me to do it, as I've got to re-review my code anyway to get a handle on the exact changes that need to be done, and it ties in with some other maintenance work I need to do :) I think for now let's focus on getting those other comments addressed, and then we can decide where to go after my review post-changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - I've taken care of removing the merge conflict & the final cast +inlining via #502, as I've been doing a bunch of refactoring today and the actual conflict was just a file being renamed.
Thanks for the PR!
* feat(rules): add .concurrent support * refactor(no-focused): remove unnecessary type cast * chore(utils): inline `isConcurrentTestCase` * chore(no-focused-tests): use static checks instead of dynamic RegExp * chore(no-focused-tests): add test case for if `concurrent` is called * chore(utils): remove body from arrow functions Co-authored-by: Leonardo Villela <[email protected]>
🎉 This issue has been resolved in version 23.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@G-Rath thanks. I wish to contribute more in the future. |
@G-Rath do you have a recommend issue that to me take? |
Refers to #432
Key points
ts
typing, i miss a TSTree definition for.concurrent
call expression. Mainly in two files above.xit
don't support use of.concurrent
, so i don't change the rules for it.xtest
don't support use of.concurrent
, so i don't change the rules for it..todo
don't support use of.concurrent
, so i don't change the rules for it.