nock: TypeError in Node 12

A quick heads up, feel free to close once you acknowledge. The test suite does not pass under node 12 (both nock latest and beta channels).

Tested using node nighly build, installed using

NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly/
nvm i node

Here’s the trace i’m getting when pre-testing my modules’ test suite relying on nock under node 12, same issue.

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type function
    at Function.from (buffer.js:218:9)
    at OverriddenClientRequest.RequestOverrider.req.write (/node_modules/nock/lib/request_overrider.js:112:27)
    at OverriddenClientRequest.RequestOverrider.req.end (/node_modules/nock/lib/request_overrider.js:133:11)
    at handleRequest (/node_modules/got/source/request-as-event-emitter.js:211:14)
    at get (/node_modules/got/source/request-as-event-emitter.js:235:5)
    at Immediate.<anonymous> (/node_modules/got/source/request-as-event-emitter.js:306:10)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 18 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@gr2m travis.yml before_script hook using patch-package module.

I am now applying this patch to nock 10.0.6 to have my CI pass under node 12. It’s probably not the complete solution tho.

The “problem” is that Buffer.from now throws on invalid inputs.

V11

> Buffer.from(()=>{})
<Buffer >

V12

> Buffer.from(()=>{})
Thrown:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type function
    at Function.from (buffer.js:219:9)
    at repl:1:8

request_overrider’s req.write should handle the “optionality” of arguments and not blindly pass them to Buffer.from

It looks like it has to do with the allowed arguments to request.end. We don’t handle the case where callback is specified but buffer and encoding are not, or where buffer and callback are provided but encoding is not.

Not sure why this is different in Node 12, though. 🤔

It would be helpful to have some more tests written from the perspective of an http client library, which check that the functions can be called in all the same ways as the native functions.