fix(server-elysia): update tests to mock node:http instead of app.listen#1284
fix(server-elysia): update tests to mock node:http instead of app.listen#1284Koushik-Salammagari wants to merge 1 commit into
Conversation
startServer() was refactored to use node:http.createServer() because
Elysia's app.listen() only works on Bun. The spec still mocked app.listen,
which was never called, causing all 6 tests to fail with EADDRINUSE.
Replace the stale app.listen mock with a vi.mock("node:http") that returns
a fake server whose listen() invokes the callback synchronously.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe test suite for ChangesElysiaServerProvider Test Mock Alignment
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Checklist
Bugs / Features
What is the current behavior?
All 6 tests in
elysia-server-provider.spec.tsfail withEADDRINUSE: address already in use 0.0.0.0:3000.startServer()was refactored to usenode:http.createServer()+server.listen()because Elysia'sapp.listen()only works on Bun. The test file still mockedmockApp.listen, which is never called by the new implementation. With no mock in place,server.listentried to bind a real port and hitEADDRINUSE.What is the new behavior?
vi.mock("node:http", ...)that returns a fake HTTP server whoselisten()invokes the success callback synchronously and whoseclose()calls its callback immediately.mockApp.listenmock and its corresponding assertions.listenthrow synchronously, which is howstartServersurfaces the error back tostart().Closes #1204
Summary by cubic
Updated Elysia server tests to mock
node:httpinstead ofapp.listen, preventing real port binding and fixing EADDRINUSE; all 6 tests now pass. Closes #1204.node:httpto return a fake server with synclistenandclose.mockApp.listenand related assertions; assertcreateServer,listen, andcloseinstead.server.listento reflectstartServerbehavior.Written for commit f5d766e. Summary will update on new commits. Review in cubic
Summary by CodeRabbit