Open sazzer opened 9 years ago
:+1:
@sazzer have you figured out any solution ?
No, but then I haven't tried it with more recent versions of Babel or Mockery since then. All I did in the end was write a helper file to just call mockery.registerAllowable for a whole bunch of core modules.
@sazzer @fustic Have you been able to get babel working with Mockery? I am using an older 5.x version of babel - still no dice.
I am running my mocha tests via Gulp's gulp-mocha plugin.
An example: I am testing a file ~//src/FileUploadManager.js. It has a dependency on ~/src/utils/FileStorageClient.js. I am mocking the require ("../utils/FileStorageClient") with mockery.
I immediately get a test failure that looks like this:
~/src/utils/FileStorageClient.js: false == true
AssertionError: src/utils/FileStorageClient.js: false == true at new Scope (node_modules/@brady/core-gulp/node_modules/babel-core/node_modules/regenerator/node_modules/recast/node_modules/ast-types/lib/scope.js:13:12)
The same tests pass if I use Proxyquire instead of Mockery, but Mockery just makes it so much easier for deep mocking.
Thanks for the input
hi @danbucholtz. I dropped usage of Mockery and I switched to https://www.npmjs.com/package/a since we had a
in the project anyway.
var fakeDep = {};
var expectRequire = require('a').expectRequire;
expectRequire('./realDep').return(fakeDep);
require('./realDep'); //returns fakeDep
@danbucholtz @fustic I've managed to get proxyquire to work with es6 modules, bit messy though:
const subject = proxyquire("../../../../../src/server/data/util/cacheMoney", {
"../../infrastructure/redis": {
"default": {
__esModule: true,
get: () => console.log("get!!!!")
}
},
"ramda": {
isNil: () => console.log("nil"),
}
}).default;
By default all warnings should be disabled. Otherwise it's too noisy and potentially doesn't play well with other modules such as babel.
When using Mockery to mock out dependencies of modules that are written in ES6 using Babel, there are a number of core Babel modules that get required automatically that need to be marked as allowed to avoid getting warnings.
The example I've found so far is using ES6 classes. When I use Mockery to mock out the dependencies of this module I still get:
I suspect there will be other core imports as well should other parts of ES6/Babel be used.