Skip to content

Centralize test imports and separate database setup - #1699

Open
stockingstocker wants to merge 5 commits into
OpenEnergyDashboard:developmentfrom
stockingstocker:issue-1692
Open

Centralize test imports and separate database setup#1699
stockingstocker wants to merge 5 commits into
OpenEnergyDashboard:developmentfrom
stockingstocker:issue-1692

Conversation

@stockingstocker

Copy link
Copy Markdown
Contributor

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:

  • timeIntervalTests.js increased from approximately 4 ms to 855 ms when importing from common.js.
  • timeValidationTests.js increased from approximately 11 ms to 11 seconds.

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])

  • Note merging this changes the database configuration.
  • This change requires a documentation update

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.)

  • I have followed the OED pull request ideas
  • I have removed text in ( ) from the issue request
  • You acknowledge that every person contributing to this work has signed the OED Contributing License Agreement and each author is listed in the Description section.

Limitations

No limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize test imports through the shared common module

1 participant