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

Created on 25 Jan 2019  路  3Comments  路  Source: facebook/jest

馃悰 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
Bug Duplicate

Most helpful comment

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.

All 3 comments

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

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.

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: https://github.com/nodejs/node/pull/20250. If you can get them to backport this to node 8 it'll fix it in that version as well 馃檪

Was this page helpful?
0 / 5 - 0 ratings