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

Increase coverage #542

Merged
merged 10 commits into from
Aug 3, 2018
Merged

Increase coverage #542

merged 10 commits into from
Aug 3, 2018

Conversation

szmarczak
Copy link
Collaborator

No description provided.

@szmarczak
Copy link
Collaborator Author

szmarczak commented Aug 2, 2018

I'll leave this part:

got/source/timed-out.js

Lines 30 to 32 in 6ba9e68

if (request[reentry]) {
return;
}

this makes us sure timed-out isn't called twice or more, although it's obvious we don't do it, so can't make a test for that.

@szmarczak
Copy link
Collaborator Author

We also need tests for electron support.

@szmarczak
Copy link
Collaborator Author

I just wonder if this piece of code is needed:

if (is.nodeStream(body) && is.buffer(body._buffer)) {
return body._buffer.length;
}

because I tried passing a Buffer as body and this doesn't even get called.

@szmarczak
Copy link
Collaborator Author

szmarczak commented Aug 2, 2018

Note: Missing test for #490 and for:

got/source/progress.js

Lines 40 to 43 in 6ba9e68

// Prevent the known issue of `bytesWritten` being larger than body size
if (uploadBodySize && uploaded > uploadBodySize) {
uploaded = uploadBodySize;
}

@szmarczak szmarczak changed the title [WIP] 100% coverage Increase coverage Aug 2, 2018
if (is.number(after)) {
after *= 1000;
if (is.nan(after)) {
after = Date.parse(error.headers['retry-after']) - Date.now();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug: at first I thought is.number won't return true for NaN, but I was wrong.

Math.max is not needed BTW.

} catch (error2) {
emitter.emit('error', error2);
}
}, backoff, options);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get() does not throw any errors directly. It uses emitter.emit('error', error);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think we need a try/catch here though: https:/sindresorhus/got/pull/542/files#diff-62bdc57f6f22ae58f495daef16f21f8bR141 In case the options.gotRetry.retries function throws.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see I've added it here. It's no longer needed because decodeURI error is catched here. If it wasn't there then we would need to catch on setTimeout too. But there's no need as metioned :)

I'll deny my answer:

It's caught here, but not here and not here.

It was caught nowhere. I don't know how I did get that 😕

To sum up: the removal is good, I'm sure 10000% :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope my answer is no confusing :P

Copy link
Owner

@sindresorhus sindresorhus Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your answer is not confusing, but you're not answering my question. To be clear, I think we need to try/catch this line because it could throw: const backoff = options.gotRetry.retries(++retryTries, error);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're not answering my question.

Sorry, if you're talking about the second one then it hadn't popped up when I was writing the answer. Pardon my confusion.

I think we need to try/catch this line because it could throw

Good point! Indeed. 🙌

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to try/catch this line because it could throw
Good point! Indeed. 🙌

And of course a test ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I hope it satisfies you :)

@sindresorhus
Copy link
Owner

because I tried passing a Buffer as body and this doesn't even get called.

You have to pass a stream. The buffer testing is testing a property on the stream.

@szmarczak
Copy link
Collaborator Author

@sindresorhus But it's converted to a stream here:

if (is.buffer(body)) {
options.body = toReadableStream(body);
options.body._buffer = body;
}

@sindresorhus
Copy link
Owner

sindresorhus commented Aug 2, 2018

@szmarczak Hmm, then maybe it returns here:

if (options.headers['content-length']) {
Add a debugger statement to each if and figure out where it returns.

@szmarczak
Copy link
Collaborator Author

Hmm, then maybe it returns here:

Yeah, you're right, checked it. So, is it needed? IMO we can get rid of that.

@sindresorhus
Copy link
Owner

sindresorhus commented Aug 2, 2018

Yeah, you're right, checked it. So, is it needed? IMO we can get rid of that.

See:

// This is the second try at setting a `content-length` header.
// This supports getting the size async, in contrast to
// https:/sindresorhus/got/blob/82763c8089596dcee5eaa7f57f5dbf8194842fe6/index.js#L579-L582
// TODO: We should unify these two at some point

This should be done in a separate PR though

test/retry.js Outdated
throw new Error('Simple error');
}
}
}), 'Simple error');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good practice to put the message in a variable and use it in both to make absolutely sure they are the same and stay the same in the future too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

@szmarczak
Copy link
Collaborator Author

This should be done in a separate PR though

So it will be :)

It's a good practice to put the message in a variable and use it in both to make absolutely sure they are the same and stay the same in the future too.

Done 🦄

@sindresorhus
Copy link
Owner

We also need tests for electron support.

Nah, don't care. If it prevents us from getting 100% test coverage, we can just mock it.

Note: Missing test for #490 and for:

Do you intend to do that in this PR? Asking so I know whether this is ready to merge or not.

@sindresorhus
Copy link
Owner

@szmarczak
Copy link
Collaborator Author

If it prevents us from getting 100% test coverage

The point is: not only that keeps us from 100%. But it's possible to achieve 99% :)

Do you intend to do that in this PR? Asking so I know whether this is ready to merge or not.

No, that'll be a separate PR too. Yes, it's ready to merge now :)

@szmarczak
Copy link
Collaborator Author

Something is failing here

AppVeyor is damn slow. Increasing the timeouts should fix the problem I think. If it does not, I'll fix it in the morning as it's 10:21 PM here.

@szmarczak
Copy link
Collaborator Author

See? Fixed :)

@sindresorhus
Copy link
Owner

Yup, AppVeyor is annoying. We had so many problems with it over at https:/avajs/ava too...

@sindresorhus sindresorhus merged commit 10d22b7 into sindresorhus:master Aug 3, 2018
@sindresorhus
Copy link
Owner

👍 I'm extra happy that doing this actually caught a couple of potential bugs.

szmarczak added a commit to szmarczak/got that referenced this pull request Aug 3, 2018
@szmarczak szmarczak deleted the 100-coverage branch January 17, 2019 18:54
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.

2 participants