Stubbing modules in test
Closed this issue · 11 comments
The last missing piece to make this boilerplate have all of the features of my non-ES6 boilerplate is the ability to stub modules in tests.
If I pull in A, and A requires B, I should be able to stub out B to be whatever I want. Proxyquire competes with Babel (they both override require
), so I was unable to figure out integrating those two.
Related: thlorenz/proxyquire#64
I just tested to see if an update to proxyquire would make it work now, and it still does not. I updated another-test.js
to begin with:
var proxyquire = require('proxyquire');
var Another = proxyquire('../../src/another', {
anotherFn: function() {
return 'pls';
},
sandwich: true
});
No dice!
If anyone is writing ES6 tests and has found a way to stub modules, I'm super curious to know your tricks!
I'm unsure if it's proxyquire + babel that are incompatible, or proxyquire + browserify (or...both?). I plan to make some isolated test cases of both to see if I can make any progress on this feature.
Webpack's method of supporting this is here: https://github.com/plasticine/inject-loader
Once webpack lands in #259 this will just be a matter of adding a page to the Wiki.
Webpack does support this for the browser tests, but obv. I'm not using webpack for the server tests. To use the same syntax for both, I'll need to build the app to run the Node tests, too, I suppose...
Example using the above module for the browser:
var MyModuleInjector = require('inject!../../src/generator-tests');
var betterName = {
name: 'sam'
};
var generatorTests = MyModuleInjector({
'./file-two': betterName
});
If I get rid of the Node tests for the browser, and instead use PhantomJS, then this is a non-issue.
I guess I should do Karma for the browser and Node for the server, exclusively?
Yup, I think so. Because of this, I'm closing this in favor of #263
Reopening because there are libraries that might work in both Node and the browser that you want to test in both scenarios. I think the only way to support that is through Browserify. So I might need to go back on all of the webpack changes for the browser tests, hah : P
Gonna figure this out in #277