GithubHelp home page GithubHelp logo

Comments (6)

richardm-stripe avatar richardm-stripe commented on June 1, 2024 3

FWIW we just changed stripe-node to play more nicely with monkey-patching by switching to the default import syntax. Figured I'd leave a note in case another library maintainer finds this issue and wanted some prior art.

from nock.

mastermatt avatar mastermatt commented on June 1, 2024

This is caused by the fact that the Stripe lib is essentially caching the native http and https module on import of NodeHttpClient, unfortunately, this means that Nock is not able to monkey patch the modules after this point.

You can get the provided tests to pass by ensuring that Nock gets required/imported first.

I know this isn't a great response, but the reality is, unless Nock gets a major rewrite, this isn't going to be fixed. The monkey patching of native modules is fundamental to Nock's design (which dates back to 2011, Node v0.4).

from nock.

ClementValot avatar ClementValot commented on June 1, 2024

I kinda fail to understand why the same code would work before the Stripe rewrite into ESM. Is this due to a difference in how node resolves import/require with cjs vs ESM?

from nock.

mastermatt avatar mastermatt commented on June 1, 2024

It has to do with their code no longer holding onto a reference to the actual exported object from the native module and instead holding a new object with all the possible imports from the module attached to it. Which means they no longer reference the object that Nock is monkey patching.

from nock.

ClementValot avatar ClementValot commented on June 1, 2024

As you indicated, changing the order of the imports "magically" fixed it :)

I don't see this easy trick mentioned anywhere in the README, maybe it should?

from nock.

ClementValot avatar ClementValot commented on June 1, 2024

That's nice of you!
I'll test that ASAP :)

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.