-
Notifications
You must be signed in to change notification settings - Fork 112
Warn Developers Lacking a Global afterEach
Function Instead of Throwing Errors
#309
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
Closed
ITenthusiasm
wants to merge
3
commits into
testing-library:main
from
ITenthusiasm:it/refactor/warn-about-after-each
Closed
Warn Developers Lacking a Global afterEach
Function Instead of Throwing Errors
#309
ITenthusiasm
wants to merge
3
commits into
testing-library:main
from
ITenthusiasm:it/refactor/warn-about-after-each
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This approach provides a much friendlier developer experience to those who want to avoid using globals. It's also less brittle.
Closing in favor of #310. However, we can re-open this if for some reason it seems more preferable.
🎉 This issue has been resolved in version 8.0.1 🎉
The release is available on:
Your semantic-release bot 📦🚀
Deleting this branch since #310 was merged.
@ITenthusiasm
ITenthusiasm
deleted the
it/refactor/warn-about-after-each
branch
November 20, 2023 15:46
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
Changes
afterEach
function instead of throwing errors.Why?
I gave some reasons for why I think this direction of change is desirable in #297 -- specifically here and here. But here's a brief set of reasons for why I think this is the way to go:
afterEach
absence check is very brittle because it only considersVitest
. If we're thinking about the longterm strength of this project, it needs to be able to consider all possible test runners. Only considering one test runner is insufficient, and bloating theif
/else
checks for every new test runner that gets released will eventually become unmaintainable. Moreover, since it's an internal implementation detail,Vitest
can change the ENV variable that they use at any moment (again, making the existing check brittle).Vitest
shares many similarities withJest
, it also has some intentional differences. For instance, Vitest intentionally refuses to use globals by default. To create a scenario in VTL that requires Vitest users to use globals (by default) goes against the natural flow of Vitest, and it may disrupt several Vitest users in the process.afterEach(cleanup)
manually if globals are not available for your test runner. The point of the documentation is to catch these exact pitfalls. If the people migrating from Jest to Vitest aren't using the Migration Guide, and if the people using VTL aren't reading the VTL docs, then there isn't really much that the maintainers can accomplish for their users. The docs are very accessible. (I used them to handle mycleanup
errors.) But the developer still has to reach for them. And maintainers can only go so far without harming other developers' experiences (e.g., throwing errors when globals aren't available) or making the logs/JSDocs overwhelming. Throwing errors harms DX while negating the point of the docs; so I feel it's best to avoid this.