mfncooper / mockery

Simplifying the use of mocks with Node.js
Other
1.1k stars 60 forks source link

Issue with webpack #37

Open OpakAlex opened 8 years ago

OpakAlex commented 8 years ago
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 commented 8 years ago

@mfncooper i need your help :)

at0g commented 8 years ago

me too

davglass commented 8 years ago

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 8 years ago

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

sheepsteak commented 8 years ago

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

Primajin commented 8 years ago

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

sheepsteak commented 8 years ago

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

Primajin commented 8 years ago

@sheepsteak ohhh instead! Thanks I was totally confused 😉

theKashey commented 6 years ago

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