Centralize test imports and separate database setup - #1699
Open
stockingstocker wants to merge 5 commits into
Open
Centralize test imports and separate database setup#1699stockingstocker wants to merge 5 commits into
stockingstocker wants to merge 5 commits into
Conversation
…ommon.js instead of direct imports
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
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.
Description
This PR standardizes test dependency imports under src/server/test while avoiding unnecessary database setup for pure unit tests.
Previously, common.js contained both shared test dependencies and database-related exports and lifecycle hooks. Importing from common.js therefore caused tests that did not use testDB, testUser, or app to still run database setup and teardown. This introduced significant overhead in some unit tests when standardizing imports across test files:
To avoid this overhead, the database-related exports and lifecycle hooks have been moved from common.js into the new commonTestDB.js.
Tests that only require shared dependencies such as chai, mocha, and expect continue to import from common.js. Tests that require database or application dependencies such as app, testUser, and testDB now import from commonTestDB.js.
This keeps shared test configuration centralized without requiring pure unit tests to initialize database resources they do not use. Tests that require database setup should have comparable runtimes to before this change, while tests that do not require it can complete significantly faster.
Repeated full runs of the test suite with npm run test confirm that the suite continues to pass after the change.
Fixes #1692
Type of change
(Check the ones that apply by placing an "x" instead of the space in the [ ] so it becomes [x])
Checklist
(Note what you have done by placing an "x" instead of the space in the [ ] so it becomes [x]. It is hoped you do all of them.)
Limitations
No limitations.