I\'m currently writing some tests for a nodejs application. assume that I have a module like this:
module.exports = function myModule(moduleParam) {
var some
Since i find tests to be a useful tool beyond unit testing and TDD (this SO answer makes a good argument), I made an npm package to help in cases like yours: require-from.
In you example this is how you would use it:
module-file.js:
function helper(param) {
return param + someVar;
}
module.exports = function myModule(moduleParam) {
var someVar;
....
....
return {
doSomething: function (bar) {
....
....
var foo = helper(bar);
....
....
}
};
};
module.helperExports = helper;
importing-file.js:
var requireFrom = require('require-from');
var helper = requireFrom('helperExports', './module-file'));
var public = requireFrom('exports', './module-file')); // same as require('./module-file')