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

Improve code coverage #162

Merged
merged 11 commits into from
Oct 9, 2019
Merged

Improve code coverage #162

merged 11 commits into from
Oct 9, 2019

Conversation

mike-marcacci
Copy link
Collaborator

@mike-marcacci mike-marcacci commented Oct 7, 2019

This removes two lines that were impossible to reach given the current state of this library. In the process, I also fixed #130. See the commit messages for details.

The point of keeping `currentStream` is to allow us to destroy it
when another terminating condition arises. These lines were here to
prevent a terminating event _arising from within the stream_ from
triggering an unnecessary call to `.destroy`.

These are no longer necessary because:

1. The way busboy works, it's impossible for a second stream to be
   created before the first has ended.
2. The busboy stream itself is no longer passed to the user,
   eliminating the possibility of user code calling `.destroy(err)`
   on the stream.
I narrowed down these tests to aborting in a Koa app. This happened
because:

1. Koa listens for the error event on the HTTP stream itself, and
   re-emits it on the app's own event emitter.
2. If there is no listener for an app error, Koa will deviate from
   the node default of crashing, and will instead log the error.
3. This particular error originates from within the HTTP stream,
   causing Koa to log the error message.

I fixed this by actually _expecting_ one error to be emit from the
app, adding an assertion to test this.
@mike-marcacci
Copy link
Collaborator Author

if (released) return

This line is used in node v10.x and v12.x but NOT in v8.x. I'm not 100% sure how to handle this from a code coverage standpoint...

@mike-marcacci
Copy link
Collaborator Author

capacitor.destroy(exitError || error)

This line could be changed to simply use error. However, in node v8.x, the order of error propagations through the HTTP stream is different, and instead of:

BadRequestError: Request disconnected during file upload stream parsing.

we get the error created by dicer:

Error: Part terminated early due to unexpected end of multipart data

This is conceptually a "secondary" error, but is the one that propagates. For this reason, we will use exitError if it's set.

We could potentially remove the || error, but there may be value in reporting any errors that are internal to the libraries that are used to manage these streams (busboy, dicer, node's stream lib, etc). So increasing coverage here may not be worth removing code designed to handle an "unexpected error," but I'll leave this to your discretion.

@jaydenseric
Copy link
Owner

Hmmm 🤔

In situations when certain code runs for particular Node.js versions, it's probably best to add an Istanbul ignore comment before it:

// istanbul ignore next

Babel has been configured to preserve such comments:

shouldPrintComment: comment =>

src/processRequest.test.mjs Outdated Show resolved Hide resolved
src/processRequest.test.mjs Outdated Show resolved Hide resolved
src/processRequest.test.mjs Outdated Show resolved Hide resolved
I added a test that uses `processRequest` directly with node's HTTP
library. In addition to being a valuable test, it adds code coverage
of the option defaults.
@mike-marcacci
Copy link
Collaborator Author

I didn't know about // istanbul ignore next. That's exactly what I needed.

I added another test in a341dc1 which uses processRequest directly. I have to step away here, so feel free to modify/update the PR as you wish! I'll be back on tomorrow :)

@mike-marcacci mike-marcacci marked this pull request as ready for review October 7, 2019 05:47
@jaydenseric jaydenseric self-requested a review October 9, 2019 01:43
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.

Errors in tests appearing for Node.js >= v10.14.2
2 participants