Skip to content

test(logger): add e2e test for ENOTFOUND error log#1233

Open
chimurai wants to merge 1 commit into
masterfrom
test-logger-e2e-ENOTFOUND
Open

test(logger): add e2e test for ENOTFOUND error log#1233
chimurai wants to merge 1 commit into
masterfrom
test-logger-e2e-ENOTFOUND

Conversation

@chimurai
Copy link
Copy Markdown
Owner

@chimurai chimurai commented May 14, 2026

add missing e2e logger test for ENOTFOUND

related: unjs/httpxy#135

Summary by CodeRabbit

  • Refactor

    • Improved type safety in error logging to ensure more precise handling of undefined targets in proxy error logs.
  • Tests

    • Added an end-to-end test verifying error logging and a 504 response when the proxy target is unreachable, asserting the logger captures the connection error details.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

This PR narrows a cast in the logger plugin so targetHref reads from (target as URL)?.href and adds an end-to-end test that asserts a 504 response and a single logger.error call with a snapshoted error message when the proxy target is unreachable.

Changes

Proxy Error Logger

Layer / File(s) Summary
Proxy error logging type safety and E2E validation
src/plugins/default/logger-plugin.ts, test/e2e/logger.spec.ts
Type cast for targetHref is narrowed from any to URL for type precision. E2E test verifies the logger formats error messages with request and target metadata when proxy targets do not exist, asserting a single logger.error call and snapshot validation.

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • chimurai/http-proxy-middleware#1215: Both PRs modify src/plugins/default/logger-plugin.ts error/proxy logging logic that formats the logged target URL (this PR adjusts targetHref casting; related PR changes URL construction to use createUrl and avoid undefined/invalid URL parts).

Poem

A rabbit logs with gentle paw,
From fuzzy any to URL law.
When targets vanish in the mist,
Tests catch errors with a list.
Hooray for types — hop, hop, hooray! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the primary change: adding an end-to-end test for ENOTFOUND error logging, which is clearly supported by the raw summary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-logger-e2e-ENOTFOUND

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

@coderabbitai coderabbitai Bot left a comment

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 `@src/plugins/default/logger-plugin.ts`:
- Line 29: The log builds targetHref unsafely by casting target to URL, causing
the string "undefined" when target is absent; change the derivation to safely
check the payload: if target is an instance of URL use target.href, else if
target is an object with a href property coerce that to string, otherwise use an
empty string (or "unknown") — update the expression where targetHref is defined
(the const targetHref in logger-plugin.ts) to perform these runtime checks
instead of an unchecked cast.
🪄 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: 2df43af5-0677-4198-906f-a9c5db46e73d

📥 Commits

Reviewing files that changed from the base of the PR and between ffbf5bd and 39cb266.

📒 Files selected for processing (2)
  • src/plugins/default/logger-plugin.ts
  • test/e2e/logger.spec.ts

Comment thread src/plugins/default/logger-plugin.ts Outdated
@chimurai chimurai force-pushed the test-logger-e2e-ENOTFOUND branch from 39cb266 to abacb50 Compare May 14, 2026 11:38
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/plugins/default/logger-plugin.ts (1)

29-29: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Test failures confirm target is undefined during ENOTFOUND errors.

The pipeline failures show the test receives "undefined" instead of "http://does-not-exist.invalid" in the logged error message. This confirms the existing review comment: when target is undefined, the cast to URL and optional chaining produce undefined, which stringifies to "undefined" in the template literal. The fix should fall back to options.target when the target parameter is absent.

🤖 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 `@src/plugins/default/logger-plugin.ts` at line 29, The logged targetHref is
becoming the string "undefined" because (target as unknown as URL)?.href yields
undefined when target is missing; change construction of targetHref to use
options.target as a fallback (e.g., derive a string from target?.href ||
options.target) so that when target is undefined the log uses options.target
instead; update the code that defines targetHref (referencing the target
variable and options.target) to coalesce to a sensible string rather than
allowing "undefined".
🤖 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.

Duplicate comments:
In `@src/plugins/default/logger-plugin.ts`:
- Line 29: The logged targetHref is becoming the string "undefined" because
(target as unknown as URL)?.href yields undefined when target is missing; change
construction of targetHref to use options.target as a fallback (e.g., derive a
string from target?.href || options.target) so that when target is undefined the
log uses options.target instead; update the code that defines targetHref
(referencing the target variable and options.target) to coalesce to a sensible
string rather than allowing "undefined".

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d0844273-3afa-4756-ae64-7ae490c8dfad

📥 Commits

Reviewing files that changed from the base of the PR and between 39cb266 and abacb50.

📒 Files selected for processing (2)
  • src/plugins/default/logger-plugin.ts
  • test/e2e/logger.spec.ts

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.

1 participant