-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 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](#5724) and [restore all mocks](#5788), 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 1. Create an empty `registerCleanupForTesting` function which should be used to register cleanup functions. 2. In `frontend/vitest.setup.ts` mock `frontend/src/lib/utils/test-support.utils.ts` such that the registered cleanup functions are called before every test. # Tests Tests only # Todos - [ ] Add entry to changelog (if necessary). not necessary
- Loading branch information
Showing
6 changed files
with
23 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// The purpose of this function is to be mocked by tests. | ||
// | ||
// Production code should use this function to register cleanup functions that | ||
// should be run before each test. | ||
export const registerCleanupForTesting = (_cleanup: () => void) => {}; |
This file contains 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 file contains 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 file contains 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 file contains 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 file contains 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