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

options.type accepts array #268

Closed
wants to merge 4 commits into from

Conversation

shawninder
Copy link
Contributor

I just forked an existing PR and added what was missing for it to be merged. See the original conversation.

Summary:
heme:

Seems like your type property in options correctly passes an array on to type-is. Wasn't immediately obvious I could do that based on the README.

dougwilson:

Awesome, thanks! Can you go ahead and also add it to all the other parsers as well? Currently I believe all their type sections are identical, so let's keep them identical.

So that's what I did. Added the change to all the other parsers as well :)

@dougwilson
Copy link
Contributor

Nice @shawninder ! I haven't dug into the changes yet, but just wanted to note that the new tests added here are failing in case you didn't realize.

README.md Outdated
@@ -132,7 +133,7 @@ to `'100kb'`.
##### type

The `type` option is used to determine what media type the middleware will
parse. This option can be a function or a string. If a string, `type` option
parse. This option can be a string, array of strings, or a function. If it is a string or array of strings, `type` option
Copy link
Contributor

Choose a reason for hiding this comment

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

wrap the line here to ~80 chars

README.md Outdated
@@ -180,7 +181,7 @@ to `'100kb'`.
##### type

The `type` option is used to determine what media type the middleware will
parse. This option can be a function or a string. If a string, `type` option
parse. This option can be a string, array of strings, or a function. If it is a string or array of strings, `type` option
Copy link
Contributor

Choose a reason for hiding this comment

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

wrap the line here to ~80 chars

README.md Outdated
@@ -243,7 +244,7 @@ than this value, a 413 will be returned to the client. Defaults to `1000`.
##### type

The `type` option is used to determine what media type the middleware will
parse. This option can be a function or a string. If a string, `type` option
parse. This option can be a string, array of strings, or a function. If it is a string or array of strings, `type` option
Copy link
Contributor

Choose a reason for hiding this comment

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

wrap the line here to ~80 chars

@shawninder
Copy link
Contributor Author

shawninder commented Sep 25, 2017

For me, the only test that fails is a test that was already failing before I made any changes. In other words, the tests added in this PR do pass, at least for me...

Here is the full output:

$ npm test

> body-parser@1.15.0 test /SOME_PATH/body-parser
> mocha --require test/support/env --reporter spec --check-leaks --bail test/



  bodyParser()
    ✓ should default to {}
    ✓ should parse JSON
    ✓ should parse x-www-form-urlencoded
    ✓ should handle duplicated middleware
    http methods
      ✓ should support ACL requests
      ✓ should support BIND requests
      ✓ should support CHECKOUT requests
      ✓ should support COPY requests
      ✓ should support DELETE requests
      ✓ should support GET requests
      ✓ should support HEAD requests
      ✓ should support LINK requests
      ✓ should support LOCK requests
      ✓ should support M-SEARCH requests
      ✓ should support MERGE requests
      ✓ should support MKACTIVITY requests
      ✓ should support MKCALENDAR requests
      ✓ should support MKCOL requests
      ✓ should support MOVE requests
      ✓ should support NOTIFY requests
      ✓ should support OPTIONS requests
      ✓ should support PATCH requests
      ✓ should support POST requests
      ✓ should support PROPFIND requests
      ✓ should support PROPPATCH requests
      ✓ should support PURGE requests
      ✓ should support PUT requests
      ✓ should support REBIND requests
      ✓ should support REPORT requests
      ✓ should support SEARCH requests
      ✓ should support SUBSCRIBE requests
      ✓ should support TRACE requests
      ✓ should support UNBIND requests
      ✓ should support UNLINK requests
      ✓ should support UNLOCK requests
      ✓ should support UNSUBSCRIBE requests
    with type option
      ✓ should parse JSON
      ✓ should parse x-www-form-urlencoded
    with verify option
      ✓ should apply to json
      ✓ should apply to urlencoded

  bodyParser.json()
    ✓ should parse JSON
    1) should fail gracefully


  41 passing (136ms)
  1 failing

  1) bodyParser.json() should fail gracefully:
     Error: expected 'Unexpected end of input' response body, got 'Unexpected end of JSON input'
      at error (node_modules/supertest/lib/test.js:265:13)
      at Test._assertBody (node_modules/supertest/lib/test.js:191:16)
      at Test._assertFunction (node_modules/supertest/lib/test.js:247:11)
      at Test.assert (node_modules/supertest/lib/test.js:148:18)
      at Server.assert (node_modules/supertest/lib/test.js:127:12)
      at emitCloseNT (net.js:1553:8)
      at _combinedTickCallback (internal/process/next_tick.js:71:11)
      at process._tickCallback (internal/process/next_tick.js:98:9)



npm ERR! Test failed.  See above for more details.

@dougwilson
Copy link
Contributor

That's strange, because master is passing in Travis CI and this PR was not. I can't merge until Travis CI passes on the PR, so whatever you think is the necessary action, please take it.

@dougwilson
Copy link
Contributor

That message looks like you are using a really old version of this module on a Node.js version that veesion doesn't support. Either use an older Node.js version or rebase this on to the current master (rebase; do not merge or I can't merge the PR).

@shawninder
Copy link
Contributor Author

I did find one of my tests wasn't passing. Didn't notice at first because the failing test was preventing the tests from going further... I can now confirm that the tests you and I added now all pass. Only the tests that previously failed still fail...

As for using a really old version of the module, I just forked your PR @dougwilson. Perhaps it was already very old or something? Anyways, my version of node shouldn't have any impact on the CI server, which shows all green now :)

@dougwilson
Copy link
Contributor

I just forked your PR @dougwilson. Perhaps it was already very old or something?

What PR? I didn't have ant PR that I'm aware of. Are you sure thr PR was mine and not someone elses? What is the date of that original PR?

@shawninder
Copy link
Contributor Author

My previous comment should have read "I just forked your PR @heme"

@dougwilson
Copy link
Contributor

Oh, I see the link to the PR at the top. The PR qas made 1 year ago, so you should not use a version of Node.js that didn't exist 1 year ago to run your test locally.

@shawninder
Copy link
Contributor Author

Only the differences I introduced show up in this PR, so it looks to me like I forked from the latest commit on master (not old at all). Am I missing something here?

@shawninder
Copy link
Contributor Author

shawninder commented Sep 25, 2017

Ah, I understand. The code is still latest, but was last developed against the a previous version of Node.js, and running the tests against my version of Node.js (v6.9.1) breaks the tests. Makes sense. Still, the CI server is seeing all tests pass. Is that sufficient to merge?

@dougwilson
Copy link
Contributor

Should be, but I haven't actually taken a look over the PR, instead spent my break time arguing about the test failures :) I have to get back to work, will check after work.

@shawninder
Copy link
Contributor Author

Sounds good man, thanks!

@dougwilson
Copy link
Contributor

Sorry I didn't get to this yesterday. I'm working to merge now, but fixing the wrapping issues and the old testing pattern that is being used that was changed.

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

Successfully merging this pull request may close these issues.

3 participants