Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Mockery with Babel transpiled ES6 modules gives lots of warnings #35

Open
sazzer opened this issue Aug 21, 2015 · 7 comments
Open

Mockery with Babel transpiled ES6 modules gives lots of warnings #35

sazzer opened this issue Aug 21, 2015 · 7 comments

Comments

@sazzer
Copy link

sazzer commented Aug 21, 2015

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:

WARNING: loading non-allowed module: babel-runtime/helpers/create-class
WARNING: loading non-allowed module: babel-runtime/core-js/object/define-property
WARNING: loading non-allowed module: core-js/library/fn/object/define-property
WARNING: loading non-allowed module: ../../modules/$
WARNING: loading non-allowed module: babel-runtime/helpers/class-call-check
WARNING: loading non-allowed module: babel-runtime/helpers/interop-require-default

I suspect there will be other core imports as well should other parts of ES6/Babel be used.

@fustic
Copy link

fustic commented Nov 3, 2015

👍

@fustic
Copy link

fustic commented Nov 3, 2015

@sazzer have you figured out any solution ?

@sazzer
Copy link
Author

sazzer commented Nov 4, 2015

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.

@danbucholtz
Copy link

@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

@fustic
Copy link

fustic commented Nov 12, 2015

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

@Dakuan
Copy link

Dakuan commented Nov 23, 2015

@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;

@stevemao
Copy link

By default all warnings should be disabled. Otherwise it's too noisy and potentially doesn't play well with other modules such as babel.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants