fix: resolve failing tests in src/index.test.ts (#30) - #32
Merged
Conversation
JRustyHaner
commented
Jul 9, 2026
Contributor
- Export app instance from index.ts for supertest usage
- Use request(app) instead of request('http://localhost:4000') to avoid race condition with async server startup
- Add mocks for initSchema, SampleModelIngestor, and auth modules
- Mock process.exit to prevent tests from terminating
- Move second test inside describe block (was incorrectly placed outside)
- Export app instance from index.ts for supertest usage
- Use request(app) instead of request('http://localhost:4000') to avoid
race condition with async server startup
- Add mocks for initSchema, SampleModelIngestor, and auth modules
- Mock process.exit to prevent tests from terminating
- Move second test inside describe block (was incorrectly placed outside)
There was a problem hiding this comment.
Pull request overview
This PR adjusts the backend entrypoint and its Vitest suite so HTTP endpoints can be tested via Supertest without relying on a race-prone real network listener.
Changes:
- Export the Express
appfromsrc/index.tsfor direct Supertest usage. - Update tests to use
request(app)and add mocks for DB/schema/ingestion/auth to avoid external side effects. - Prevent accidental test termination by stubbing
process.exit, and fix test structure by placing the second test inside thedescribeblock.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| backend/src/index.ts | Exports the Express app instance so it can be imported by tests. |
| backend/src/index.test.ts | Switches to request(app) and adds additional mocks to stabilize the test environment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dotenv.config(); | ||
|
|
||
| const app = express(); | ||
| export const app = express(); |
Comment on lines
+53
to
+55
| // 7. Mock process.exit to prevent tests from exiting | ||
| vi.spyOn(process, "exit").mockImplementation((() => undefined) as never); | ||
|
|
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.