msw
msw copied to clipboard
Headers created before `server.listen()` are not being considered after changed with `headers.set()` or `headers.append()`
Prerequisites
- [X] I confirm my issue is not in the opened issues
- [X] I confirm the Frequently Asked Questions didn't contain the answer to my issue
Environment check
- [X] I'm using the latest
msw
version - [X] I'm using Node.js version 18 or higher
Node.js version
v20.17.0
Reproduction repository
https://github.com/diego-aquino/msw-headers-init-repro-with-vitest
Reproduction steps
- Clone the reproduction repository
-
npm install
-
npm run test
Current behavior
The README.md
of the reproduction repository contains a more detailed explanation. Here's a summary:
I created two identical test suites, except for the imported MSW version:
-
passing-on-v2.4.3.test.ts
- This suite is using[email protected]
and passes. -
failing-on-v2.4.9.test.ts
- This suite is using[email protected]
and fails.
Before starting the MSW server, each suite creates a Headers
instance with initial values, appends a new header and checks if the initial values are preserved and the instance contains the correct values.
After starting the server with server.listen()
, the suites append yet another header to the instance and re-run the checks. With [email protected]
, the existing values are preserved and the new header is appended. However, the current headers are lost with [email protected]
when used in a Request
or fetch
call. The only kept header is the one appended after starting the server, as if the instance was empty before.
The problem does not appear to occur when using the headers directly, because only the last expect reading the headers from a Request
fails.
Expected behavior
For headers created before server.listen()
, Request
and fetch
should consider their previous values after changed with set
or append
. This was the behavior with [email protected]
and appears to have changed in [email protected]
and later.
Let me know if there is anything unclear I could clarify!