GithubHelp home page GithubHelp logo

Comments (7)

b-brefeld avatar b-brefeld commented on June 1, 2024

@VladimirChuprazov

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.

mikicho avatar mikicho commented on June 1, 2024

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.

b-brefeld avatar b-brefeld commented on June 1, 2024

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 from 2024-02-07 15-38-57

Screenshot when using nock 13.5.1
Screenshot from 2024-02-07 15-32-06

You tried both versions and don't have this behavior?
I'm running on Ubuntu 22.04 if it makes any difference

from nock.

mikicho avatar mikicho commented on June 1, 2024

@b-brefeld This is because request is async. You should await for the response.

from nock.

b-brefeld avatar b-brefeld commented on June 1, 2024

@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.

mikicho avatar mikicho commented on June 1, 2024

@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.

VladimirChuprazov avatar VladimirChuprazov commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.