-
Notifications
You must be signed in to change notification settings - Fork 351
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
Not handling some binary responses correctly (with reproduction) #278
Comments
@moltar are you on |
I have installed the latest ( My understanding is that the latest version fixed a bug about binary requests, not responses. Thanks. |
Interestingly, the value is stored correctly: "content": {
"mimeType": "application/octet-stream",
"size": 118,
"text": "1f8b08000000000000008be65250a806620505a5c49292a2cca4d292d414e7fcbcb2d4a2e2ccfcbc62439314252b053333431d88a2e4c4dc82c4ccf43c4f90b0a1a181998591a5b18191a5a1b1b9295045ad0e71e6991a6133cfc8ccd8d8c8d8d0c0c8d8c2dcc8c41c641e572c00c734cd0ea2000000"
} And fetching via curl https://scaleleap-pup-screenshots.s3.ca-central-1.amazonaws.com/report2.json.gz | xxd -plain | tr -d '\n'
Have compared the strings, they are definitely equal. |
What I am noticing: const arrBuf = await res.arrayBuffer()
console.log('byteLength', arrBuf.byteLength) When running without Polly, the Edit: added a test for that in my demo repo |
Added a Jest snapshot to the test repo. It has the correct response representation when running without Polly, but with Polly contents seem to be not right. Not sure what the contents represent, but they have a are different value. |
This seems to be related! |
Downgrading |
Also experiencing this issue @moltar. Have you happened to find out anything further? Thanks in advance. |
Looking into it. Should hopefully have a solution in the next few days. |
Reproducible example: // test.js
const fetch = require('node-fetch');
const { Polly } = require('@pollyjs/core');
const NodeHttpAdapter = require('@pollyjs/adapter-node-http');
const FsPersister = require('@pollyjs/persister-fs');
Polly.register(NodeHttpAdapter);
Polly.register(FsPersister);
describe('test', () => {
let polly = new Polly('test', {
adapters: ['node-http'],
persister: 'fs',
});
afterAll(() => polly.stop());
it('test', async () => {
const response = await fetch('http://perdu.com/');
const text = await response.text();
console.log(text);
});
}); echo '{}' > package.json
npm i @pollyjs/[email protected] @pollyjs/[email protected] @pollyjs/[email protected] [email protected] [email protected]
npx jest test.js Results in:
The error disappears when uncommenting the Polly.js block. This is the best MWE I could find; the bug disappears without jest or node-fetch for me. |
Went down a pretty deep rabbit hole which led me to the issue coming from here: That line returns false where it would actually return true if they used This is now dependent on nock/nock#1850 |
Released with |
Thank you very much! |
@offirgolan Thanks a ton for chasing it down the hole! :) |
Sorry to necrobump, but it's a pity https://github.com/moltar/polly-octet-stream is no longer there, I'm struggling to figure how to mock a binary response and it could've helped me. |
Description
Requests fail when fetching binary data.
The binary data seems to be fetching and recording fine. But then it is somehow wrong, because when passing gzip'ed data to the zlib, it complains that the data is not valid.
So the data is either transformed or cut off in some way.
Shareable Source
See https://github.com/moltar/polly-octet-stream
Error Message & Stack Trace
Config
Using
@spotify/polly-jest-presets
.The config it ships with:
https://github.com/spotify/polly-jest-presets/blob/master/src/index.ts
Dependencies
From: https://github.com/spotify/polly-jest-presets/blob/master/package.json
Copy the @pollyjs dependencies from
package.json
:Relevant Links
https://github.com/moltar/polly-octet-stream
Environment
The text was updated successfully, but these errors were encountered: