Revert Errors Regarding Missing Global Hooks #310
Merged
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.
This PR effectively reverts the changes in #297, and it serves as the ideal over #309. Note that I've had my changes reverted before and I know it isn't the most pleasurable experience. So please hear out my justification for this suggestion. It's not a petty change. It's a change that I believe benefits the VTL users overall. (Some of the points below are mentioned here and here in #297.)
Justification
afterEach
absence check is very limited 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 our existing check brittle).afterEach
will never appear. If that ever happens, throwing/logging errors/warnings whenafterEach
is missing will simply be inaccurate.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 and negates the point of the docs; so I feel it's best to avoid this.afterEach
function is missing. So to include such functionality in VTL will be unexpected for many developers. Originally, I opened Warn Developers Lacking a GlobalafterEach
Function Instead of Throwing Errors #309 in light of fix: log globals warning only once react-testing-library#1252. However, this change was reverted in fix: revert missing hooks warnings react-testing-library#1255 for reasons similar to what I mentioned earlier. This is why I closed Warn Developers Lacking a GlobalafterEach
Function Instead of Throwing Errors #309 and am opening this PR.I think what we're experiencing right now is a season in which developers are trying out new testing tools besides Jest. And having been used to things generally "just working" for so long, there may be some who do not prefer to reach for the documentation. However, the documentation is there for a reason. In Open Source, there are some GitHub Issues that get opened, but that ultimately just get closed with a comment saying, "We explain this in the docs". For this scenario, this should probably be the approach that VTL takes. Otherwise, we'll create a more difficult DX and an inconsistent TL experience for a set of VTL users -- eventually engendering issues like testing-library/react-testing-library#1253. (Again, the docs are exactly for this use case.)