Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor(expect-expect): clean up and use ESQuery syntax #171

Merged
merged 1 commit into from
Oct 2, 2018

Conversation

macklinu
Copy link
Collaborator

@macklinu macklinu commented Oct 2, 2018

This PR refactors to use selector syntax. Open to feedback on if this is a helpful refactor! 😄

Relates to #158, #169, #170

@macklinu macklinu requested review from SimenB and thymikee October 2, 2018 21:16
'CallExpression[callee.name=/^it|test$/]'(node) {
unchecked.push(node);
},
[`CallExpression[callee.name=/^${assertFunctionNames.join('|')}$/]`]() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This statement replaces the isExpectCall() function (same behavior).

},
[`CallExpression[callee.name=/^${assertFunctionNames.join('|')}$/]`]() {
// Return early in case of nested `it` statements.
for (const ancestor of context.getAncestors()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved from using Array#some() to using a for..of loop because it felt more semantically correct. When we find the element we are looking for, call unchecked.splice() then break, instead of returning true in Array#some().

@macklinu macklinu merged commit 0276985 into master Oct 2, 2018
@macklinu macklinu deleted the esquery/expect-expect branch October 2, 2018 22:33
@SimenB
Copy link
Member

SimenB commented Oct 14, 2018

🎉 This PR is included in version 21.24.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants