mfncooper/mockery

Issue with webpack

OpakAlex opened this issue · 9 comments

ERROR in ./~/mockery/mockery.js
Module not found: Error: Cannot resolve module 'module' in /private/var/www/coders51/mta-components/node_modules/mockery
 @ ./~/mockery/mockery.js 39:8-25

Any ideas? Thanks!

@mfncooper i need your help :)

at0g commented

me too

Sorry, I didn't see this. I've never attempted to use mockery in the browser, is that what you are trying to do? mockery is designed to only work in Node as it uses a lot of the core Node infrastructure under the hood to mock the require statements which are not the same as the ones in the browser.

at0g commented

@davglass Thanks for your reply, I understand that require in the browser does not make.
My build was targeting node using common js 2 (no UMD).
Specifically I was creating a [node] bundle for testing with mocha cli and wanted to use mockery to mock deps.

I've managed to mock modules using inject-loader (https://github.com/plasticine/inject-loader) before in Webpack.

@sheepsteak Can you explain how you got this to run with mockery in webpack? I am not able to extrapolate from the readme.md of inject-loader onto how to inject mockery into webpack.

@Primajin I just used inject-loader instead of mockery. If you don't want to do that you could just run your tests outside of webpack with the mocha/jasmine CLI.

@sheepsteak ohhh instead! Thanks I was totally confused 😉

There is a mocking library with mockery-compatible API, which can handle webpack as well -> https://github.com/theKashey/rewiremock