Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest is causing multiple HTTP cookie headers to be merged into one cookie value. #7700

Closed
JasonCust opened this issue Jan 25, 2019 · 4 comments
Labels

Comments

@JasonCust
Copy link

JasonCust commented Jan 25, 2019

🐛 Bug Report

When using Jest with the request lib (I also tried node-fetch and saw the same issue) to test a server response with multiple cookies returned, Jest will join the cookies into one string in the response object. Removing Jest resolves the issue.

To Reproduce

Steps to reproduce the behavior: See Repl link below. Local test server works as expected without Jest.

index.js will execute the same logic without Jest first and the header is as expected. It will then execute the code through a Jest test file which then munges the set-cookie header value when multiple cookies are sent.

Expected behavior

With a response header including multiple cookies (e.g. "foo=bar" and "bar=foo"), expect the response object from request to have a header value for set-cookie to be an array of those cookies (e.g. ["foo=bar", "bar=foo"]). However with Jest, the example header value would be ["foo=bar,bar=foo"].

Link to repl or repo (highly encouraged)

A demo.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.2
    CPU: (8) x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
  Binaries:
    Node: 8.11.1 - ~/.nvm/versions/node/v8.11.1/bin/node
    npm: 6.5.0 - ~/.nvm/versions/node/v8.11.1/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0
@JasonCust
Copy link
Author

Updated demo code to use http module for making a request and the issue is still present once Jest is introduced.

@JasonCust JasonCust changed the title Jest causing multiple cookie header to be munged into one string Jest is causing multiple HTTP cookie headers to be merged into one cookie value. Jan 25, 2019
@grosto
Copy link
Contributor

grosto commented Jan 27, 2019

The bug is most likely with node, prior v10. Jest runs every test suite with vm module. if you run your code as vm script without Jest, the same error occurs.

image

Upgrading node will solve the issue. I tested in node v10.10.0 and it behaves as expected.

@SimenB
Copy link
Member

SimenB commented Jan 27, 2019

Yeah, this is essentially a dupe of #2549. The case of http is fixed in Node 10 since they switched from instanceof Array to Array.isArray here: nodejs/node#20250. If you can get them to backport this to node 8 it'll fix it in that version as well 🙂

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants