-
-
Notifications
You must be signed in to change notification settings - Fork 969
Description
tough-cookie integration broken in Jest
- Node.js version: 13.9.0
- OS & version: Darwin 18.7.0
A got
call with a tough-cookie
CookieJar
where the response has a set-cookie
header rejects if run in Jest. The repro repo below contains both a yarn start
script that runs in plain Node and succeeds, and a yarn test
script that runs the same code in Jest.
#811 was closed in favor of jestjs/jest#4305, however it seems that, at least after the got refactor, util.promisify
itself in Jest is not the problem - got's role in this appears to be the "Horrible tough-cookie
check" - removing the following !Reflect.has
conditional (making the two assignments unconditional) resolves the issue.
got/source/normalize-arguments.ts
Line 172 in 41795d7
if (!Reflect.has(setCookie, promisify.custom)) { |
However, I would not dare to make that change without input from @szmarczak or @sindresorhus because I do not have context on what it is there to guard against in the first place.
Jest's new role in this is very likely due to something like jestjs/jest#2549, but that is unlikely to be fixed in Jest anytime soon.
Actual behavior
Rejects with
TypeError: cb is not a function
at next (node_modules/tough-cookie/lib/cookie.js:1090:9)
at MemoryCookieStore.Object.<anonymous>.MemoryCookieStore.putCookie (node_modules/tough-cookie/lib/memstore.js:124:3)
at withCookie (node_modules/tough-cookie/lib/cookie.js:1109:13)
at MemoryCookieStore.Object.<anonymous>.MemoryCookieStore.findCookie (node_modules/tough-cookie/lib/memstore.js:61:12)
at CookieJar.Object.<anonymous>.CookieJar.setCookie (node_modules/tough-cookie/lib/cookie.js:1113:9)
at internal/util.js:297:30
at node_modules/got/dist/source/request-as-event-emitter.js:76:90
at Array.map (<anonymous>)
at ClientRequest.handleResponse (node_modules/got/dist/source/request-as-event-emitter.js:76:47)
at ClientRequest.origin.emit (node_modules/@szmarczak/http-timer/dist/source/index.js:39:20)
Expected behavior
Sets the cookie into the cookie jar with no error.
Code to reproduce
https://github.com/jeysal/got-tough-cookie-jest-bug-repro
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.