-
Notifications
You must be signed in to change notification settings - Fork 135
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: add no-manual-cleanup rule #72
Conversation
README.md
Outdated
@@ -142,6 +144,7 @@ To enable this configuration use the `extends` property in your | |||
| [no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | ![angular-badge][] ![react-badge][] ![vue-badge][] | | | |||
| [no-dom-import](docs/rules/no-dom-import.md) | Disallow importing from DOM Testing Library | ![angular-badge][] ![react-badge][] ![vue-badge][] | ![fixable-badge][] | | |||
| [no-get-by-for-checking-element-not-present](docs/rules/no-get-by-for-checking-element-not-present) | Disallow the use of `getBy*` queries when checking elements are not present | | | | |||
| [no-manual-cleanup](docs/rules/no-manual-cleanup.md) | Disallow the use of `cleanup` | ![react-badge][] ![vue-badge][] | | |
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 don't think we should enable this rule for any shareable config for reasons explained in the original issue.
lib/rules/no-manual-cleanup.js
Outdated
}, | ||
messages: { | ||
noManualCleanup: | ||
"`cleanup` is performed automatically after each test by {{library}}, you don't need manual cleanups.", |
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 is not right: the automatic cleanup is performed depending on your testing framework, not on your testing library package. This rule should just mention that manual cleanups are dissalowed as the testing framework taking care of it automatically.
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.
While it's true the automatic cleanup is performed depending on the testing framework, not all testing libraries package have a cleanup
method, like Angular's testing library.
It does not make sense for me to make this rule fire even if the testing library package doesn't have a cleanup
method.
I agree this rule should be removed from shareable configs as we don't know the test runner used though.
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.
Fair enough about short-circuiting when importing from a testing library package without cleanup
, but still the error message is wrong as the one handling the automatic cleanup is the testing framework (e.g. jest), not testing library package (e.g. @testing-library/angular
).
(Damn, "testing library" and "testing framework" are not making easier this discussion).
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.
Sure, I'll fix it too, thanks for the feedback! 👍
By the way, there are some rules like no-debug
where we don't support frameworks like Svelte Testing Library, we should probably open a new issue to include them.
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.
That's actually one of the reasons I don't like to write code for checking specific testing library packages as if a new one comes up tomorrow we could have to update rules. I prefer to leave them agnostic from any package, specially those not enabled by default, so users can set them up under their responsibility. Of course, we should mention in proper rule doc which are those testing library packages supposed to be compatible with the rule for clarification.
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.
What I meant is that we have shareable configs for Angular, Vue, etc. But we are not adding any support for Svelte, Preact, etc. I think we should extend the rules that already work with specific packages (such as no-debug, or no-dom-import) to other potential testing libraries 🙂
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.
Ah of course 🤦♂️
And probably we should open an issue about including more frameworks for sure!
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.
Awesome implementation for this rule and nice bunch of tests! Just asked for an additional doc reference.
|
||
## Further Reading | ||
|
||
- [cleanup API in React Testing Library](https://testing-library.com/docs/react-testing-library/api#cleanup) |
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.
Can you add skipping auto cleanup here:
Skipping Auto Cleanup
🎉 This PR is included in version 2.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #63