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.
Motivation
Our unit tests have always been quite brittle because we need to remember to clean up all global state between each test.
Often tests fail when run in a different order because one test accidentally depends on state left behind by other tests.
This has improved a lot now that we always reset all stores and restore all mocks, but there are still other cleanups that need to be performed in tests.
This PR proposes a generic way of registering a cleanup in the file that defines the thing that needs to be cleaned up, instead of in every test. As a proof of concept, it is then used to automatically call
resetMockedConstants();
in every test that (transitively) imports$tests/utils/mockable-constants.test-utils.ts
.Changes
registerCleanupForTesting
function which should be used to register cleanup functions.frontend/vitest.setup.ts
mockfrontend/src/lib/utils/test-support.utils.ts
such that the registered cleanup functions are called before every test.Tests
Tests only
Todos
not necessary