Skip to content

fix(server-elysia): update tests to mock node:http instead of app.listen#1284

Open
Koushik-Salammagari wants to merge 1 commit into
VoltAgent:mainfrom
Koushik-Salammagari:fix/elysia-test-node-http
Open

fix(server-elysia): update tests to mock node:http instead of app.listen#1284
Koushik-Salammagari wants to merge 1 commit into
VoltAgent:mainfrom
Koushik-Salammagari:fix/elysia-test-node-http

Conversation

@Koushik-Salammagari
Copy link
Copy Markdown

@Koushik-Salammagari Koushik-Salammagari commented May 15, 2026

PR Checklist

  • The commit message follows the conventional-commit convention

Bugs / Features

What is the current behavior?

All 6 tests in elysia-server-provider.spec.ts fail with EADDRINUSE: address already in use 0.0.0.0:3000.

startServer() was refactored to use node:http.createServer() + server.listen() because Elysia's app.listen() only works on Bun. The test file still mocked mockApp.listen, which is never called by the new implementation. With no mock in place, server.listen tried to bind a real port and hit EADDRINUSE.

What is the new behavior?

  • Add vi.mock("node:http", ...) that returns a fake HTTP server whose listen() invokes the success callback synchronously and whose close() calls its callback immediately.
  • Remove the dead mockApp.listen mock and its corresponding assertions.
  • The "startup errors" test now makes the fake server's listen throw synchronously, which is how startServer surfaces the error back to start().
  • All 6 tests pass.

Closes #1204


Summary by cubic

Updated Elysia server tests to mock node:http instead of app.listen, preventing real port binding and fixing EADDRINUSE; all 6 tests now pass. Closes #1204.

  • Bug Fixes
    • Mock node:http to return a fake server with sync listen and close.
    • Remove dead mockApp.listen and related assertions; assert createServer, listen, and close instead.
    • Make the startup error test throw from server.listen to reflect startServer behavior.

Written for commit f5d766e. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • Tests
    • Updated test suite for the server provider to improve mock assertion accuracy and better reflect actual server behavior.

Review Change Stack

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.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

⚠️ No Changeset found

Latest commit: f5d766e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65b34faf-9212-42f0-b03f-d1d89b4e649e

📥 Commits

Reviewing files that changed from the base of the PR and between 08414ed and f5d766e.

📒 Files selected for processing (1)
  • packages/server-elysia/src/elysia-server-provider.spec.ts

📝 Walkthrough

Walkthrough

The test suite for ElysiaServerProvider was refactored to correctly mock the Node.js HTTP server layer after the implementation migrated from Elysia's app.listen() to http.createServer() + server.listen(). All test mocks and assertions now align with the HTTP server-based startup and shutdown flow.

Changes

ElysiaServerProvider Test Mock Alignment

Layer / File(s) Summary
HTTP Server Mock Infrastructure and App Surface
packages/server-elysia/src/elysia-server-provider.spec.ts
Introduced mockHttpServer with mocked listen and close methods, added vi.mock("node:http") override so createServer returns the mock, and adjusted the shared mockApp fixture by removing the listen mock and adding fetch to align with the provider's HTTP-server-based behavior.
Server Lifecycle and Error Handling Test Updates
packages/server-elysia/src/elysia-server-provider.spec.ts
Updated start/stop test assertions to validate that Node's createServer is called and mockHttpServer.listen is invoked with (3000, "0.0.0.0", callback); adjusted per-test localMockApp in the custom endpoints test to remove listen and add fetch; updated the error test to throw from mockHttpServer.listen instead of app.listen, preserving the port release assertion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The server once relied on Elysia's call,
But Node.js said "I'll handle it all!"
Now mocks match the truth—HTTP server's the way,
And tests run in green, huzzah! Hip-hooray! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating tests to mock node:http instead of app.listen, which directly addresses the primary objective.
Description check ✅ Passed The description comprehensively covers what was broken, why, and how it was fixed, with proper issue linking and checklist completion for applicable items.
Linked Issues check ✅ Passed The PR fully addresses issue #1204 by mocking node:http.createServer, removing dead app.listen mocks, and ensuring all six failing tests now pass.
Out of Scope Changes check ✅ Passed All changes are scoped to the test file and directly address the requirements in issue #1204; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

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.

[BUG] Elysia server provider test suite entirely broken — stale mocks after Node.js HTTP refactor

1 participant