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
- Support req.end with callback only According to docs, `req.end` can accept callback as a first argument. That's what `got` module does. Fixes #1509 ``` request.end([data[, encoding]][, callbac... — committed to gugu/nock by gugu 5 years ago
- Support req.end with callback only According to docs, `req.end` can accept callback as a first argument. That's what `got` module does. Fixes #1509 ``` request.end([data[, encoding]][, callback])# ... — committed to gugu/nock by gugu 5 years ago
- fix: Fix `req.end(cb)`; prevent TypeError in Node 12 (#1547) According to the docs, `req.end` can accept callback as a first argument. That's what `got` module does. Closes #1509 ``` request.e... — committed to nock/nock by gugu 5 years ago
- ⬆️ Upgrade dependency: nock * nock@10.0.6 -> nock@11.0.0-beta.13 Addressed this bug: https://github.com/nock/nock/issues/1509 — committed to sounisi5011/metalsmith-netlify-published-date by sounisi5011 5 years ago
- fix: Fix `req.end(cb)`; prevent TypeError in Node 12 (#1547) According to the docs, `req.end` can accept callback as a first argument. That's what `got` module does. Closes #1509 ``` request.e... — committed to nock/nock by gugu 5 years ago
- fix: Fix `req.end(cb)`; prevent TypeError in Node 12 (#1547) According to the docs, `req.end` can accept callback as a first argument. That's what `got` module does. Closes #1509 ``` request.e... — committed to nock/nock by gugu 5 years ago
- fix: Fix `req.end(cb)`; prevent TypeError in Node 12 (#1547) According to the docs, `req.end` can accept callback as a first argument. That's what `got` module does. Closes #1509 ``` request.end([d... — committed to nock/nock by gugu 5 years ago
@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.fromnow throws on invalid inputs.V11
V12
request_overrider’s req.write should handle the “optionality” of arguments and not blindly pass them to
Buffer.fromIt looks like it has to do with the allowed arguments to
request.end. We don’t handle the case wherecallbackis specified butbufferandencodingare not, or wherebufferandcallbackare provided butencodingis 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.