Code Monkey home page Code Monkey logo

Comments (3)

jhnns avatar jhnns commented on May 10, 2024

Yes, I see the advantages. It's more likely to change a variable name than the dependency.

But I think your suggestion is impossible to implement because rewire does no static analysis of your code. Thus it doesn't know which variables are referencing which module. The only way to accomplish this is by mapping the dependency-paths on module startup like node-sandboxed-module does:

var foo = rewire("./foo.js", {
    "./util.js": utilMock
});

But if your prefer this approach I think it would be better to just use node-sandboxed-module 😉.

Personally I came to the conclusion that after all unit-tests are usually gray-box-tests. Basically you are aware of the implementation but you're trying to test it like you didn't know. If you're changing the implementation you'll likely need to adjust the unit-test as well.

I like your idea, but I don't know how to implement it.

from rewire.

wnr avatar wnr commented on May 10, 2024

Okay, thanks for your answer. Too bad I can't have the best of rewire and sandboxed-module. I think I'm gonna stick with rewire either way since I really like the non-eval approach :)

Interesting about the gray-box-testing. Never thought about that in that way, but I guess it makes sense.

from rewire.

jhnns avatar jhnns commented on May 10, 2024

Nevermind, it's always good to discuss about improvements 👍

from rewire.

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.