thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
152 stars 24 forks source link

When I left one of the required modules unstubbed, it's not calling the original module #63

Closed gsalisi closed 7 years ago

gsalisi commented 7 years ago

foo.js

const bar = require('app/bar.js');
const model = require('./model.js');

fooSpec.js

const bar = require('app/bar.js');
const proxyquire = require('proxyquireify')(require);
const foo = proxyquire('./foo.js', {
    './model.js': {
        test: 'yay'
    }
});

bar in foo.js is an empty object. bar in fooSpec.js is the correct data. model gets mocked to { test: 'yay } properly

Why is it that bar is not calling through properly?

bendrucker commented 7 years ago

What's data? Can't make sense of your example and exactly what's wrong here. If possible a runnable example is very helpful.

gsalisi commented 7 years ago

Sorry about that, I updated the names. I just want to verify that not stubbing a required file actually fetches the original required file. It doesn't seem to work for me.

bendrucker commented 7 years ago

bar.js isn't a legal require statement unless you have an npm module called bar.js. Should be ./bar.js if it's a local file. Is that it?

gsalisi commented 7 years ago

I am requiring a local file. For this case let's pretend it is at app/js/bar.js. This is getting stubbed to an empty object instead of using the original require.

bendrucker commented 7 years ago

Please update your original example then. It's not valid as is and I can't be sure what's going on if I don't know what you're running. Again, a runnable example is by far the fastest way for us to get you help.

gsalisi commented 7 years ago

I am using karma for running the tests with browserify with the following config:

config.set({
        basePath : basePath,
        frameworks: [ 'browserify', 'jasmine' ],
        exclude: exclude,
        files: files,
        preprocessors: preprocessors,
        browserify: {
            debug: true,
            plugin: [
                ['remapify', [{
                    src: '**/*.js',
                    expose: appName,
                    cwd: clientRoot + '/' + appName
                }, {
                    src: '**/*.js',
                    expose: 'dxtest',
                    cwd: clientRoot + '/dxtest'
                }, {
                    src: '**/*.js',
                    expose: 'dxcore',
                    cwd: clientRoot + '/dxcore'
                }]],
                'proxyquireify/plugin'
            ],
            transform: [
                ['babelify', {
                    ignore: ['dxcore/lib/**/*.js'],
                    blacklist: ['es6.tailCall']
                }]
            ],
            watch: true
        },
        ...
}

If none of this stands out to you as a cause to my issue, feel free to close this ticket and I will opt to not use this library. To clarify, the issue is it's not calling through unstubbed/uspecified files as expected.

bendrucker commented 7 years ago

Ok, I can't really make sense of what's going on. If you can't provide a runnable example it's too hard for me to diagnose.