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

feat(rules): add .concurrent support #498

Conversation

leonardovillela
Copy link
Contributor

@leonardovillela leonardovillela commented Dec 30, 2019

Refers to #432

Key points

  • Maybe a little over test, but i tried to main the same logic for test scenarios.
  • In some places i cheat in 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.
    • This one i opened a issue on jest, just to check if it's a valid behavior.
  • 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.

@leonardovillela
Copy link
Contributor Author

@G-Rath and @SimenB

@G-Rath G-Rath self-assigned this Dec 30, 2019
Copy link
Collaborator

@G-Rath G-Rath left a 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 😄)

isSupportedAccessor(callee.property, 'only');
isSupportedAccessor(
isConcurrentExpression(callee)
? (callee.parent as TSESTree.MemberExpression).property
Copy link
Collaborator

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.

getNodeName(expression) &&
new RegExp(
`(${validTestCaseNames.join('|')})\.${TestCaseProperty.concurrent}`,
).test(getNodeName(expression) as string);
Copy link
Collaborator

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.

]);

const isConcurrentExpression = (expression: TSESTree.Node) =>
getNodeName(expression) &&
new RegExp(
Copy link
Collaborator

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)
Copy link
Collaborator

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.

@leonardovillela
Copy link
Contributor Author

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.

@G-Rath
Copy link
Collaborator

G-Rath commented Jan 2, 2020

@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.

Copy link
Collaborator

@G-Rath G-Rath left a 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!

@G-Rath G-Rath closed this Jan 4, 2020
G-Rath added a commit that referenced this pull request Jan 4, 2020
* 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 <leonardo.villela37@gmail.com>
@G-Rath G-Rath mentioned this pull request Jan 4, 2020
github-actions bot pushed a commit that referenced this pull request Jan 4, 2020
# [23.3.0](v23.2.0...v23.3.0) (2020-01-04)

### Features

* **rules:** add .concurrent support ([#498](#498)) ([#502](#502)) ([dcba5f1](dcba5f1))
@github-actions
Copy link

github-actions bot commented Jan 4, 2020

🎉 This issue has been resolved in version 23.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@leonardovillela leonardovillela deleted the add-concurrent-support branch January 4, 2020 11:20
@leonardovillela
Copy link
Contributor Author

@G-Rath thanks. I wish to contribute more in the future.

@leonardovillela
Copy link
Contributor Author

@G-Rath do you have a recommend issue that to me take?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants