Skip to content

test(elysia): mock node http server in provider spec#1358

Open
asdaxzcwqsa wants to merge 1 commit into
VoltAgent:mainfrom
asdaxzcwqsa:fix/elysia-test-http-mocks
Open

test(elysia): mock node http server in provider spec#1358
asdaxzcwqsa wants to merge 1 commit into
VoltAgent:mainfrom
asdaxzcwqsa:fix/elysia-test-http-mocks

Conversation

@asdaxzcwqsa

@asdaxzcwqsa asdaxzcwqsa commented Jun 24, 2026

Copy link
Copy Markdown

Summary

  • update the Elysia provider tests to mock node:http.createServer() instead of the old app.listen() path
  • assert against the mocked Node server's listen() / close() lifecycle
  • keep the startup-error test aligned with the current implementation by throwing from the mocked HTTP server

Problem

startServer() now creates a Node HTTP server directly, but the spec file still mocked and asserted on app.listen(). That leaves the real HTTP server path unmocked during tests and causes the suite to hit EADDRINUSE instead of exercising the provider logic.

Notes

This PR only updates the test suite to match the current Node-based startup flow.

Fixes #1204


Summary by cubic

Updated Elysia provider tests to mock node:http.createServer() and assert the Node server listen/close lifecycle, aligning with the current startup path and preventing EADDRINUSE. Fixes #1204.

Written for commit d9a42db. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Updated server lifecycle tests to verify startup and shutdown behavior through the underlying server instance.
    • Improved coverage for startup errors and port release handling.
    • Adjusted custom endpoint test setup to match the new server mocking approach.

@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d9a42db

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

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The test file elysia-server-provider.spec.ts is updated to mock node:http's createServer instead of app.listen. A mockServer object with listen, close, once, and listening is introduced, wired as the return value of createServer. Assertions, error simulation, and per-test fixtures are adjusted to match.

Changes

Elysia Server Provider Test Fix

Layer / File(s) Summary
node:http mock and mockServer fixture setup
packages/server-elysia/src/elysia-server-provider.spec.ts
Adds createServer import and vi.mock("node:http"), declares a mockServer variable in describe scope with listen/close/once/listening stubs, removes listen from mockApp, and returns mockServer from vi.mocked(createServer) in beforeEach.
Updated assertions and error paths
packages/server-elysia/src/elysia-server-provider.spec.ts
Rewrites start/stop test assertions to verify createServer was called and mockServer.listen/mockServer.close were invoked; removes per-test listen mock from localMockApp; updates startup-error test to throw from mockServer.listen instead of mockApp.listen.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 The old mock pointed left, the server went right,
So tests all tumbled into EADDRINUSE night.
I hopped to node:http, swapped the mock with care,
Now createServer answers — no stale method there!
Six tests pass cleanly, the rabbit hops free. 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: mocking the Node HTTP server in the Elysia provider spec.
Description check ✅ Passed The description covers summary, problem, notes, and the linked issue, so it mostly fulfills the template despite omitted checklist details.
Linked Issues check ✅ Passed The changes address #1204 by mocking node:http.createServer, asserting listen/close lifecycle, and aligning the startup-error test.
Out of Scope Changes check ✅ Passed The diff appears limited to the Elysia provider spec and stays within the issue scope with no unrelated code changes.
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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/server-elysia/src/elysia-server-provider.spec.ts`:
- Line 29: The test setup currently uses an untyped mockServer variable, which
removes the safety of the node:http contract. Update the mock in
elysia-server-provider.spec.ts to use a typed shape such as Pick<Server,
"listen" | "close" | "once" | "listening">, and keep the mock object aligned
with the methods/properties exercised by the Elysia server provider tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6775c905-933f-4ab0-9a48-0ec403459a51

📥 Commits

Reviewing files that changed from the base of the PR and between 17732a3 and d9a42db.

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


describe("ElysiaServerProvider", () => {
let provider: ElysiaServerProvider;
let mockServer: any;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the spec file and nearby related implementation to check whether `any` is necessary.
git ls-files 'packages/server-elysia/src/*' | sed -n '1,200p'
printf '\n--- spec outline ---\n'
ast-grep outline packages/server-elysia/src/elysia-server-provider.spec.ts --view expanded || true
printf '\n--- spec excerpt ---\n'
cat -n packages/server-elysia/src/elysia-server-provider.spec.ts | sed -n '1,220p'
printf '\n--- provider outline ---\n'
ast-grep outline packages/server-elysia/src/elysia-server-provider.ts --view expanded || true
printf '\n--- provider excerpt ---\n'
cat -n packages/server-elysia/src/elysia-server-provider.ts | sed -n '1,260p'

Repository: VoltAgent/voltagent

Length of output: 14398


Replace mockServer: any with a typed server mock. any drops type safety in this test file; use a Pick<Server, "listen" | "close" | "once" | "listening"> (or similar) so the mock stays aligned with node:http.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/server-elysia/src/elysia-server-provider.spec.ts` at line 29, The
test setup currently uses an untyped mockServer variable, which removes the
safety of the node:http contract. Update the mock in
elysia-server-provider.spec.ts to use a typed shape such as Pick<Server,
"listen" | "close" | "once" | "listening">, and keep the mock object aligned
with the methods/properties exercised by the Elysia server provider tests.

Source: Coding guidelines

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

Copy link
Copy Markdown
Contributor

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