Conversation
📝 WalkthroughWalkthroughThe pull request refactors test infrastructure across 18+ test files, replacing hardcoded Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
test/test-utils.ts (1)
24-33: Usevi.spyOn()foremitto maintain consistency and preserve EventEmitter return behavior.Line 29 replaces
emitoutright withvi.fn(), unlike the other methods on lines 31–33 which usevi.spyOn(). This inconsistency also drops the method's boolean return value. While the current test doesn't depend on this, usevi.spyOn(clientRequest, 'emit').mockImplementation(() => true)to keep the pattern consistent and avoid masking potential event-flow issues.Suggested patch
export function createMockClientRequest( ...args: ConstructorParameters<typeof ClientRequest> ): ClientRequest { const clientRequest = new ClientRequest(...args); - clientRequest.emit = vi.fn(); + vi.spyOn(clientRequest, 'emit').mockImplementation(() => true); vi.spyOn(clientRequest, 'setHeader'); vi.spyOn(clientRequest, 'write'); vi.spyOn(clientRequest, 'destroy'); return clientRequest; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/test-utils.ts` around lines 24 - 33, The test helper createMockClientRequest currently replaces clientRequest.emit with vi.fn(), breaking consistency and losing the EventEmitter boolean return; change that to use vi.spyOn(clientRequest, 'emit').mockImplementation(() => true) instead of direct assignment, keeping the other spies (setHeader, write, destroy) as-is so emit preserves its return value and follows the same spy pattern.test/e2e/router.spec.ts (1)
123-139: Test name may be stale after refactoring.The test is named "missing a ':' in protocol will cause it to use https" but the implementation now uses
target.protocolwhich includes the colon (e.g.,"https:"). The test still passes because HTTPS is used, but the name no longer reflects what's being tested.Consider renaming to better reflect the current behavior:
📝 Proposed name update
- it('missing a ":" in protocol will cause it to use https', async () => { + it('should work with URL-derived protocol', async () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/e2e/router.spec.ts` around lines 123 - 139, Rename the test case whose title is "missing a ':' in protocol will cause it to use https" to accurately reflect that the router callback returns target.protocol (which includes the colon, e.g., "https:"), for example "router returning protocol with colon uses https" or similar; update the it(...) description where createProxyMiddleware is invoked and the router callback returns { host: target.hostname, port: target.port, protocol: target.protocol } so the test name matches the actual behavior being asserted.test/unit/fix-request-body.spec.ts (1)
160-176:proxyResponseis unused in this test.The
proxyResponsemock is created on line 168 but is never passed tofixRequestBody(). The assertion on line 173 (expect(proxyResponse.end).toHaveBeenCalledTimes(0)) will always pass trivially sinceproxyResponseis not involved in the function under test.Consider removing this dead code or clarifying the test intent:
♻️ Proposed fix to remove unused mock
it('should not fixRequestBody() when there bodyParser fails', () => { const proxyRequest = fakeProxyRequest(); const request = { get readableLength() { return 4444; // simulate bodyParser failure }, } as BodyParserLikeRequest; - const proxyResponse = createMockResponse(); proxyRequest.setHeader('content-type', 'application/x-www-form-urlencoded'); fixRequestBody(proxyRequest, request); - expect(proxyResponse.end).toHaveBeenCalledTimes(0); expect(proxyRequest.write).toHaveBeenCalledTimes(0); expect(proxyRequest.destroy).toHaveBeenCalledTimes(0); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/unit/fix-request-body.spec.ts` around lines 160 - 176, The test creates an unused proxyResponse mock and asserts on it even though fixRequestBody(proxyRequest, request) never receives it; remove the dead proxyResponse variable and its assertion (expect(proxyResponse.end)...), or if you intended to assert behavior on the response, pass that mock into fixRequestBody and update the function call accordingly. Locate the proxyResponse declaration in the test and either delete its creation and the expect(proxyResponse.end).toHaveBeenCalledTimes(0) line, or change the call to fixRequestBody(proxyRequest, request, proxyResponse) and adjust fixRequestBody to accept and use that third parameter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/e2e/router.spec.ts`:
- Around line 123-139: Rename the test case whose title is "missing a ':' in
protocol will cause it to use https" to accurately reflect that the router
callback returns target.protocol (which includes the colon, e.g., "https:"), for
example "router returning protocol with colon uses https" or similar; update the
it(...) description where createProxyMiddleware is invoked and the router
callback returns { host: target.hostname, port: target.port, protocol:
target.protocol } so the test name matches the actual behavior being asserted.
In `@test/test-utils.ts`:
- Around line 24-33: The test helper createMockClientRequest currently replaces
clientRequest.emit with vi.fn(), breaking consistency and losing the
EventEmitter boolean return; change that to use vi.spyOn(clientRequest,
'emit').mockImplementation(() => true) instead of direct assignment, keeping the
other spies (setHeader, write, destroy) as-is so emit preserves its return value
and follows the same spy pattern.
In `@test/unit/fix-request-body.spec.ts`:
- Around line 160-176: The test creates an unused proxyResponse mock and asserts
on it even though fixRequestBody(proxyRequest, request) never receives it;
remove the dead proxyResponse variable and its assertion
(expect(proxyResponse.end)...), or if you intended to assert behavior on the
response, pass that mock into fixRequestBody and update the function call
accordingly. Locate the proxyResponse declaration in the test and either delete
its creation and the expect(proxyResponse.end).toHaveBeenCalledTimes(0) line, or
change the call to fixRequestBody(proxyRequest, request, proxyResponse) and
adjust fixRequestBody to accept and use that third parameter.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a58b97b3-1385-4d10-9d6d-fddfc829b614
📒 Files selected for processing (16)
test/e2e/hono.spec.tstest/e2e/http-proxy-middleware.spec.tstest/e2e/http-server.spec.tstest/e2e/path-rewriter.spec.tstest/e2e/plugins.spec.tstest/e2e/response-interceptor.spec.tstest/e2e/router.spec.tstest/e2e/websocket.spec.tstest/test-utils.tstest/unit/fix-request-body.spec.tstest/unit/path-filter.spec.tstest/unit/path-rewriter.spec.tstest/unit/response-interceptor.spec.tstest/unit/router.spec.tstest/unit/utils/function.spec.tsvitest.config.ts
💤 Files with no reviewable changes (1)
- vitest.config.ts
Summary by CodeRabbit
Tests
Chores