Skip to content

test(lambda-edge): expand handler unit tests for createRequest, createResult, and env bindings#4747

Open
rokasta12 wants to merge 1 commit intohonojs:mainfrom
rokasta12:feat/lambda-edge-handler-tests
Open

test(lambda-edge): expand handler unit tests for createRequest, createResult, and env bindings#4747
rokasta12 wants to merge 1 commit intohonojs:mainfrom
rokasta12:feat/lambda-edge-handler-tests

Conversation

@rokasta12
Copy link
Copy Markdown
Contributor

Summary

Expands unit test coverage for the Lambda@Edge handler from 5 tests to 33 (28 new). All new tests target untested code paths in handler.ts.

New coverage by area

isContentTypeBinary — 9 additional MIME types via it.each (csv, html+charset, xml variants, octet-stream, pdf, audio, video)

createBody — 4 new tests:

  • PUT/DELETE/PATCH methods (non-GET/HEAD with body)
  • Non-base64 (text) encoding
  • Undefined requestBody
  • Empty data string

createRequest (tested indirectly via handle) — 6 new tests:

  • Host fallback to distributionDomainName when host header is absent
  • Querystring appended to URL
  • No trailing ? when querystring is empty
  • CloudFront headers converted to Request headers
  • No body for GET requests
  • Base64 body decoding for POST requests

createResult (tested indirectly via handle) — 6 new tests:

  • Status returned as string (CloudFront requirement)
  • Non-200 status codes
  • No bodyEncoding for text content
  • bodyEncoding: 'base64' for binary content
  • Response headers in CloudFront format
  • 404 for unmatched routes

env bindings — 4 new tests:

  • Event, config, request passed as env bindings
  • Callback invocation
  • No-throw when callback is not provided (optional chaining)
  • Context passed as env binding

Coverage

Metric Before After
Statements 100%
Branches 96.66%
Functions 100%
Lines 100%

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.50%. Comparing base (2de30d7) to head (24a6f64).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4747      +/-   ##
==========================================
+ Coverage   91.48%   91.50%   +0.01%     
==========================================
  Files         177      177              
  Lines       11556    11556              
  Branches     3357     3359       +2     
==========================================
+ Hits        10572    10574       +2     
+ Misses        983      981       -2     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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