-
Notifications
You must be signed in to change notification settings - Fork 258
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
Remove request library #275
base: master
Are you sure you want to change the base?
Conversation
this does not work yet, throws 400, something about the content-type i guess, looking at it. |
could someone with deeper insight in the coveralls api please have a look at this? in my tests it returned 422: failed to parse package.json. i have a deadline on the 22.2. that i will likely miss, so i can not really investigate this earlier than that. thanks. |
lib/request.js
Outdated
|
||
res.on('end', () => { | ||
if (!errored) { | ||
cb(null, { statusCode }, body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is brittle, because you'll get mochibake if any character boundaries get split. I'd recommend doing it this way instead:
const body = []
res.on('data', chunk => body.push(chunk))
res.on('end', () => {
if (!errored) {
cb(null, { statusCode }, Buffer.concat(body).toString())
}
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! i read about this years ago and forgot again, now i will remember it as the pattern to use.
lib/request.js
Outdated
}); | ||
|
||
// Write data to request body | ||
req.write(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the request was POST-ing as a urlencoded form, but here, you're just posting the JSON data raw without any prefix.
So, eg, if the object was {foo: 'bar'}
, then previously, the post body would've been json=%7B%22foo%22%3A%22bar%22%7D
, but now it's {"foo":"bar"}
.
That's almost certainly why it's failing.
Try something like this:
req.write(`json=${encodeURIComponent(data)}`)
Hey, I'd like to see this fixed as soon as possible, since request's deprecation just starting causing tap to raise deprecation notices at install time, because of this dependency. Added some comments to where I think the patch is going wrong. I'd recommend adding some tests around it, it's pretty ironic for this of all modules to not have full test coverage :) |
thanks! having a look at this now, looks like the obvious reason. |
i assume this confirms that the http request works: https://coveralls.io/builds/28723334 coverage went down, the request file can be seen in the sources. will see if i can get some tests done quickly. |
had a look at this and it's a bit more complicated than i would be comfortable to just implement. have not worked with mocha/sinon for years, the seemingly logical choice to use would be nock as a mock for http.request. i will revisit tomorrow, it's almost 2 in the morning here anyways. |
added nock to dev dependencies, this makes the test on node 6 break, added a few tests for the request file, made sure the body chunks are buffers, Buffer.concat and nock did not play well together, |
@jaeh can you rebase, squash and remove any unrelated changes? You have a change in test/getOptions.js that is causing tests to fail. Also you have updated all devDependencies which is also causing tests to fail. As for nock and Node.js, can't you use an older nock version? |
NVM, I rebased it and pushed it on my fork master...XhmikosR:remove-request Only issue left is Node.js 6.x compatibility. @nickmerwin how about dropping support for Node.js 6.x and even 8.x so that we can move on and make the new release a major version bump? |
I tried nock 10.x without any luck. Maybe we just look into using another library to replace request and keep it simple? |
Anyone looking to fix this issue, I released a fork of this library called coveralls-next as we were not getting the support we needed on this repo. https://github.com/jtwebman/coveralls-next |
if (!errored) { | ||
cb(null, { statusCode }, Buffer.concat(body).toString()); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How i would have written it:
let body = ''
for await (const chunk of res) {
body += chunk
}
cb(null, { statusCode }, body)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also take the opportunity to use Promise instead
} | ||
|
||
if (typeof data !== 'string') { | ||
cb(new Error('request.post(url, data, cb): data must be a String.')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise + throw instead? Do think this is kind of verbose
Since this library doesn't seem to be supported anymore I fix a bunch of things on a fork if you want to check it out and are still pulling the library into your packages: https://github.com/jtwebman/coveralls-next IE no more request library and no security issues. |
please do not merge this without testing,
i have not yet tested this in any of my libraries,
just made the unit tests pass,
will do so in the course of today then repost here.
there also are some function calls and returns that could be made simpler,
i tried to keep the changes minimal for now.
this would close #204, #267 and likely others i did not see.