Skip to content

test: preserve Content-Type in stubFetch response clone on Deno 2.x#159

Merged
zimeg merged 1 commit into
mainfrom
fix/response-clone-content-type-deno2
Jul 2, 2026
Merged

test: preserve Content-Type in stubFetch response clone on Deno 2.x#159
zimeg merged 1 commit into
mainfrom
fix/response-clone-content-type-deno2

Conversation

@zimeg

@zimeg zimeg commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

This pull request fixes a test (v2.x) failure in the Deno CI matrix caused by a Response.clone() behavior change on Deno 2.x.

  • On Deno 2.x, Response.clone() drops headers set from a plain object literal (e.g. { "Content-Type": "application/json" }). Headers set via a Headers instance survive.
  • stubFetch returned response.clone() directly, so a stubbed response built with plain-object headers lost its Content-Type — breaking testing/http_test.ts on v2.x (response.headers.get("Content-Type") returned null).
  • Fix: reconstruct the response from a fresh new Headers(response.headers) copy so the stub preserves headers regardless of how the caller built the Response.
  • Also set fail-fast: false on the Deno test matrix — the v2.x failure was cancelling the v1.x and v1.46.2 jobs, hiding that those versions actually passed.

testing

  • Check out this branch and run deno task test — the full suite (fmt, lint, 37 tests) passes on Deno 2.x, where stubFetch's "should replace global fetch with a stub" previously failed.
  • Confirm the Deno CI matrix now reports each version (v1.x, v1.46.2, v2.x) independently rather than cancelling siblings on first failure.

Special notes

Root cause isolated with a minimal repro: a Response built with headers: { "Content-Type": "application/json" } returns null for that header after .clone() on Deno 2.x, while the same built with new Headers({...}) preserves it.

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've ran deno task test after making the changes.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.96%. Comparing base (a5e5839) to head (4b397eb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #159   +/-   ##
=======================================
  Coverage   96.95%   96.96%           
=======================================
  Files          39       39           
  Lines        1643     1648    +5     
  Branches       25       25           
=======================================
+ Hits         1593     1598    +5     
  Misses         47       47           
  Partials        3        3           

☔ View full report in Codecov by Harness.
📢 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.

@zimeg
zimeg force-pushed the fix/response-clone-content-type-deno2 branch from b4e5b04 to e1b67f5 Compare July 1, 2026 14:18
@zimeg zimeg changed the title fix: preserve Content-Type in stubFetch response clone on Deno 2.x test: preserve Content-Type in stubFetch response clone on Deno 2.x Jul 1, 2026
On Deno 2.x, `Response.clone()` drops headers set from a plain object
literal (e.g. `{ "Content-Type": "application/json" }`), so `stubFetch`
returned a cloned response with a missing Content-Type. This surfaced as
a `test (v2.x)` failure in the Deno CI matrix, which — with the default
fail-fast — cancelled the v1.x and v1.46.2 jobs too.

Reconstruct the response from a fresh `Headers` copy so the stubbed
response preserves its headers regardless of how the caller built it, and
set `fail-fast: false` on the Deno test matrix so each version reports
independently.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg
zimeg force-pushed the fix/response-clone-content-type-deno2 branch from e1b67f5 to 4b397eb Compare July 1, 2026 14:18
@zimeg zimeg added bug Something isn't working semver:patch requires a patch version number bump github_actions Pull requests that update GitHub Actions code labels Jul 1, 2026
@zimeg zimeg self-assigned this Jul 1, 2026
@zimeg
zimeg marked this pull request as ready for review July 1, 2026 14:19
@zimeg
zimeg requested a review from a team as a code owner July 1, 2026 14:19
@zimeg

zimeg commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

🗣️ Unblocks #157 and #158

@zimeg
zimeg enabled auto-merge (squash) July 1, 2026 14:19

@WilliamBergamin WilliamBergamin 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.

Nice fix 💯

@zimeg
zimeg merged commit 9bf5d70 into main Jul 2, 2026
28 checks passed
@zimeg
zimeg deleted the fix/response-clone-content-type-deno2 branch July 2, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working github_actions Pull requests that update GitHub Actions code semver:patch requires a patch version number bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants