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
credentials
config not supported in node?
#189
Comments
Hey, @kentcdodds! Thank you for raising this. I think the culprit here is that an intercepted request in Node doesn't have the same properties as the one issued in a browser. To comply with the promised Lines 32 to 49 in 4a49e73
Since you use fetch, I can assume either jsdom, or something like |
JSDOM does not support fetch so I'm using whatwg-fetch. |
I'm pretty sure it also relies on https://github.com/github/fetch/blob/74e4fe8a4731b4e233ac7da42c960a351fd3400f/fetch.js#L507-L511 I'd have to research what XHR does with |
After some investigation, I don't think there's a reliable way to propagate the Request issuerDepending on the request issuing library you use to polyfill
|
That's too bad. Well, I suggest do the best we can and document the limitation. I wonder if whatwg-fetch would be open to a contribution to handle this considering this is not compliant to the spec and compliance is the goal. |
That is not the issue with if (['same-origin', 'include'].includes(options.credentials) {
xhrRequest.withCrendetials = true
} // in a different universe, that knows only about `xhrRequest`:
if (xhrRequest.withCredentials) {
interceptedRequest.credentials = 'same-origin' // but can also be 'include'
} The original input to |
Hmmm... But in a real scenario, if I make a |
Sorry for jumping in to an ongoing discussion like this, but in a real scenario, wouldn't you receive cookies or not receive cookies on the server? I don't think you can tell from the request what setting it had initially. |
Yeah, I've personally never used the credentials field, so I really don't know. I'm just thinking that if they're trying to simulate real fetch, they're missing something here. But perhaps it's not possible for some reason? |
So just thinking out loud here: The options for
Now, in node you don't really have the concept of a host origin (unless I'm misunderstanding something, or jsdom has implemented something for this!), so it seems to me that the behavior In msw however, I would expect the behavior to look like what it would look like on the server, for instance including the cookies in the request if |
What they are doing that might be debated though, is assuming |
Interesting! In any case, it seems that this is out of scope for this module and it's actually up to the polyfill to deal with this. Also, it's not critically important to me anyway so I'll go ahead and just close this. Thanks for the discussion everyone :) |
Describe the bug
When I set the
credentials
config infetch
to'omit'
that isn't passed along to thereq
.Environment
msw: 0.0.18
nodejs: 12
npm: 6.14.5
To Reproduce
kentcdodds/bookshelf@b733434#diff-47664a78a0147eab6cc64883365d1ef4R75-R76
Expected behavior
I expect the request.credentials to bet set to what is set in the
window.fetch
call.The text was updated successfully, but these errors were encountered: