Comments (7)
Here is a repo that reproduces the issue as requested:
https://bitbucket.org/brefeld-computers/nock-2575/src/main/
After cloning the repo run the following command:
npm install && npm run build && npm test
The test should fail.
Now change the "nock" version number to 13.5.0 in the package.json and run command:
npm run clean && npm install && npm run build && npm test
The test should now succeed.
If you need more info, you know where to find me
from nock.
You didn't end
your request in your example. This is working for me:
request({method: 'GET', host: hostname, path: pathname, timeout: 5000}, (res) => {
console.log(res.statusCode)
}).end();
from nock.
Dear Michael,
Thanks for your info.
I changed the code and tried again. (see: link)
I still have a failing test with nock on 13.5.1
Screenshot when using nock 13.5.0
Screenshot when using nock 13.5.1
You tried both versions and don't have this behavior?
I'm running on Ubuntu 22.04 if it makes any difference
from nock.
@b-brefeld This is because request
is async. You should await for the response.
from nock.
@mikicho request
does not return a Promise and I can't use await for it.
However I changed the code again to allow awaiting a response.
Please see the link
I still experience the same behaviour
from nock.
@b-brefeld are you using ESM?
If yes, your example imports the http
module before nock
does due to how ESM resolves and runs the code.
You can work around this like this:
import nock from 'nock';
const { request } = await import('http');
Another option is to import
nock before:
node --import nock test.js
But, I recommend you use 3rd party libraries like axios
or got
instead of directly using the http
module, which would probably solve this without your notice.
from nock.
Hi @b-brefeld I just checked your reproduction repo, as @mikicho suggested, with both axios and got it works fine, I tried it.
Another option which @mikicho suggested is to run node --import nock test.js
, if you want to run all your tests you can try:
node --import nock node_modules/.bin/jasmine
it works in your repo.
from nock.
Related Issues (20)
- Reporting a vulnerability HOT 2
- Incompatible with node 18 HOT 7
- Support AbortSignal in http requests
- Convenience method to match all HTTP verbs
- enableNetConnect does not work w nock.recorder.rec() HOT 1
- [Node 18.12] Class extends value undefined is not a constructor or null HOT 2
- incompatible behaviour introduced with v13.3.2 HOT 17
- Interceptors not being removed in 13.3.2 HOT 2
- Replace npm debug with require('node:util').debuglog HOT 2
- Remove lodash HOT 1
- Application to become a nock maintainer. HOT 5
- Expand function fails on weird GET query params HOT 4
- reqheaders does not work when using an undefined requestBody HOT 3
- Add interceptor at the beginning of list
- Return 500 instead of 404 HOT 4
- Bun support for nock.disableNetConnect() HOT 1
- POST request with ReadStream request body does not return a response HOT 10
- Disabled discussions HOT 6
- Improve debug logging HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nock.