mockery icon indicating copy to clipboard operation
mockery copied to clipboard

Issue with webpack

Open OpakAlex opened this issue 9 years ago • 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!

OpakAlex avatar Sep 24 '15 11:09 OpakAlex

@mfncooper i need your help :)

OpakAlex avatar Sep 24 '15 12:09 OpakAlex

me too

at0g avatar Sep 30 '15 09:09 at0g

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.

davglass avatar Oct 06 '15 19:10 davglass

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

at0g avatar Oct 10 '15 02:10 at0g

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

sheepsteak avatar Apr 12 '16 16:04 sheepsteak

@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 avatar Aug 10 '16 10:08 Primajin

@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 avatar Aug 10 '16 15:08 sheepsteak

@sheepsteak ohhh instead! Thanks I was totally confused 😉

Primajin avatar Aug 11 '16 07:08 Primajin

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

theKashey avatar Jan 09 '18 09:01 theKashey