-
Notifications
You must be signed in to change notification settings - Fork 109
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
Throw error when running vitest with no afterEach global and no VTL_SKIP_AUTO_CLEANUP #297
Conversation
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.
Looking good! I'd love to have some tests that prove that the behavior works as expected
Thank you! |
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.
@afontcu good to merge this up?
Hey! sorry for the delay. Taking a look back at this, I'm not 100% sure about throwing an error if people use Vite without globals. What if they prefer not to use them? Vite offers that option for a reason, and I don't think Testing Lib should be enforcing a specific config (that is not actually mandatory to function). Maybe adding docs is good enough? Is there a way to enable auto-cleanup in Vite without requiring user config, as we do in Jest? |
In that case, they have an option to explicitly acknowledge that they're missing out on the auto-cleanup by setting
I would argue that it isn't, because people migrating from Jest to Vitest would expect it to work the same as it was working before and might not notice that.
I don't think so, because the current Jest approach relies on global hooks being exposed. |
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.
Hi folks, I know this issue has been here for a few months, I was away for a while but now I'm back.
So, I wanted to:
- Double check if the fix is still valid nowadays. If so, I'll go ahead and merge it.
- Discuss if this should be labeled as a major release as it includes a breaking change – I'd love to avoid that, but seems like some people might have been relying on previous behavior (even if not expected) and adding a throw there might break their current suites. wdyt?
I haven't checked, but doubt any of this changed so issue is likely to be still valid.
I can see how this can be a breaking change, yeah. Most quality-focused teams would probably like to be notified about this issue tho. Maybe by deprecating previous versions. Maybe it can be made a warning in this major, and then an error in the next major. Up to you. |
🎉 This PR is included in version 8.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Released a new major to include this PR as is – thanks for working on this, @Maxim-Mazurok! |
@Maxim-Mazurok Hi, shouldn't the condition introduced here also contain a check for whether |
Yeah, that's a good point, looks like you do have to enable globals in order to skip cleanup. I don't see why would anyone want to skip it tho. Having tests that affect each other is pretty bad, imagine seeing errors when running all tests, and then not seeing errors when trying to debug failing test, that would be a headscratcher. So the main value of my PR was to alert developers that expected auto-cleanup doesn't work without globals. One could add an option to skip cleanup without globals, probably would be good to add a test similar to the ones added in this PR, and it should be a pretty straightforward task. I don't really want to do it as I don't see value in that, but I guess it won't hurt. |
@afontcu @Maxim-Mazurok Sorry to pop-in after the fact. I wasn't aware of this PR until I saw the major version bump in
I agree. Granted, some people coming to Vitest are migrating from Jest, yes. But Vitest (at least currently) seems to have its own philosophy. Part of that is seen in how I am quite content to use the When I was testing the
This is not the intention of the |
IMO most developers using VTL will expect auto-cleanup to work out of the box, so the goal was to alert them when auto-cleanup (which is enabled by default) can't happen (due to lack of globals). For those rare cases when people don't care about auto-cleanup - it's fair to ask them to disable it explicitly IMO. I think it makes sense, if auto-cleanup is enabled - it needs globals. If there are no globals - it can't work, so error should occur. Because you expect system to use auto-cleanup but it can't. Hope this helps, cheers! |
I understand your line of reasoning. But my concern is that this breaking change:
Vitest already provides documentation regarding the Testing Library Globals. On the other side, well-documented integrations like STL also document this topic. This seems to be the approach that others are going with, and it worked for me when I migrated from Jest to Vitest. Personally, my vote would be for this change to be reverted. It seems to already be an inconvenience for other devs (like |
Addressed in 1bbeeb4 |
This partially addresses #296 and will make more sense after docs are updated