Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Remove request library #275

wants to merge 19 commits into from

Conversation

jaeh
Copy link

@jaeh jaeh commented Feb 13, 2020

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.

@jaeh
Copy link
Author

jaeh commented Feb 13, 2020

this does not work yet, throws 400, something about the content-type i guess, looking at it.

@jaeh
Copy link
Author

jaeh commented Feb 16, 2020

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);
Copy link

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())
  }
})

Copy link
Author

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);
Copy link

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)}`)

@isaacs
Copy link

isaacs commented Mar 8, 2020

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 :)

@jaeh
Copy link
Author

jaeh commented Mar 10, 2020

thanks! having a look at this now, looks like the obvious reason.

@jaeh
Copy link
Author

jaeh commented Mar 11, 2020

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.

@jaeh
Copy link
Author

jaeh commented Mar 11, 2020

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.

@jaeh
Copy link
Author

jaeh commented Mar 14, 2020

added nock to dev dependencies, this makes the test on node 6 break,
maybe using sinon to mock the requests would be a better idea.

added a few tests for the request file,
only the happy path and some obvious errors that now get caught before even sending the request (url or data empty or not strings)

made sure the body chunks are buffers, Buffer.concat and nock did not play well together,
because nock seems to send strings.

@XhmikosR
Copy link
Contributor

XhmikosR commented Apr 24, 2020

@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?

@XhmikosR
Copy link
Contributor

XhmikosR commented Apr 24, 2020

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?

@XhmikosR
Copy link
Contributor

I tried nock 10.x without any luck. Maybe we just look into using another library to replace request and keep it simple?

@jtwebman
Copy link

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());
}
});

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)

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.'));
Copy link

@jimmywarting jimmywarting May 30, 2021

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

@jtwebman
Copy link

jtwebman commented Mar 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace request lib?
5 participants