-
Notifications
You must be signed in to change notification settings - Fork 236
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
fix: support all variations of describe
, it
, & test
#792
Conversation
(Have made this a draft PR for now, but tbh it's ready to go) |
src/rules/utils.ts
Outdated
return node.callee.tag.object.type === AST_NODE_TYPES.MemberExpression | ||
? isTestCaseName(node.callee.tag.object.object) | ||
: isTestCaseName(node.callee.tag.object); |
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 sure there's a way to restructure this so we don't have to duplicate the condition in two different branches, but can't figure it out.
I'm also sure that the same restructure will be usable in no-focused-tests
(as it has pretty much the exact same conditional structure)
Just realised I should have tests covering not supported methods, i.e (as I expected: it fails on |
9911ff8
to
96fd19a
Compare
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.
great stuff 👍
// if we're an `each()`, ensure we're being called (i.e `.each()()`) | ||
if ( | ||
node.callee.type !== AST_NODE_TYPES.TaggedTemplateExpression && | ||
node.parent?.type !== AST_NODE_TYPES.CallExpression && |
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.
there's no issue with ?
potentially making this undefined at the check true
?
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.
It shouldnt no - parent
currently never can actually be undefined
anyway, it's just marked as such because of TypeScript reasons.
There's typescript-eslint/typescript-eslint#1417 which tracks wanting to improve the typings for parent
.
@@ -0,0 +1,424 @@ | |||
import { TSESLint } from '@typescript-eslint/experimental-utils'; |
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.
great idea to have this test 👍 My only "complaint" is that it will potentially not help us discover dead code, but probably worth it
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 we should still be able to find deadcode, just not in these methods. I plan to split the utils up into their own files under utils/*
at some point, which'll also help.
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.
iirc jest
doesn't support any kind of "don't collect coverage from files/tests" ay?
Thinking about it, we should be able to rig CI to run this test specifically in its own job, and skip it when running the coverage-collecting tests
I had a think about this, and think we should be able to do something in CI to cover that?
I think I might make this a There's already a few rules this technically fixes their support for |
adding a few tests to the other rules to verify would be sweet |
#798 made me realise this doesn't address a big inconsistency that's not highlighted by the tests: the i.e with a rule that has a
with this source code:
You would get this output:
This is because This is a really subtle difference that I really want to get rid of because it's something I don't want to have to think about - I think the better behaviour would be to match I think it should be straightforward to implement this behaviour, but will look to do that in a follow PR as I think this is nice by its own, and I could also be wrong 🤷 |
👍 |
f0d9460
to
9ce4e24
Compare
@SimenB I think this is good to go - I've been through most of the rules to find which ones are improved by this refactor, and added a couple of test cases to each that fail with the old guards. I've also refactored the utils test to have less duplication and be more unit-y - we can always make new tests if we come up with specific cases to test. Part of the final refactor is also because I've written a patch for including testing I'll merge this in a few minutes since I'd like to move on with more refactoring, but happy to discuss and revert/make changes if you've got any review comments :) |
describe
& test
describe
, it
, & test
## [24.3.4](v24.3.3...v24.3.4) (2021-04-05) ### Bug Fixes * support all variations of `describe`, `it`, & `test` ([#792](#792)) ([0968b55](0968b55))
🎉 This PR is included in version 24.3.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
We've had a bit of flurry of activity in the last few weeks which has resulted in some of our technical debt coming to the surface, so this is (hopefully) the start of me addressing some of that.
There are two main goals with this refactor:
node
is a call i.e it'll result injest
doing "something".each
, because of.each()
- while that looks like a call (and technically is), it's not the "right" kind of call we're wanting to match with these methods.Because in a perfect world I'd like this to be the last time I have to think twice about this when using these methods, I've implemented a set of tests using an inline eslint rule to ensure we're matching every possible variation of calls and not-calls for these methods.
The end result was
lowercase-name
losing a point of cover due to not having a test that covers when the names are not strings, and a few "valid" cases forvalid-describe
failing as they're now actually supported (🎉).Because I'd like to land this as a refactor commit by itself for now, I've renamed the methods so that I can keep the old
isDescribe
around forvalid-describe
to use - I'll be refactoring it once this is landed to support the new guards.It's also technically a more accurate name anyway 🤷
Because of the interlocking nature of things, I've picked this as a starting point and deliberately ignored other possible refactors as I think it'll be premature to do them in one lump go - this is why I'm not doing any deduplication on the methods (since they now actually share pretty much the exact same implementation) nor touched the types or other util functions.
My goal is to have this as a stable starting point that I can build other refactors & fixes up around :)