Open ncuillery opened 9 years ago
Good idea ! :+1:
Feel free to make a PR :wink:
I use in webpack.config
:
new webpack.DefinePlugin({
...
__IS_MOCKED__: JSON.stringify(argv.env.mock),
}),
And inside my src/index.js
:
if(__IS_MOCKED__) {
require('./mocks');
}
The mocks
folder index file will have the mock configuration together with superagent-mock
require.
The uglification process will remove it from the production build (provided no --env.mock was added to its build script)
Don't see it as "dirty" so much.
It's okay to write these two lines of code
in test files (preprocessor, beforeEach or whatever) but when you use superagent-mock in a client app (running in the browser), you had to append these lines somewhere in your source files.
How about a webpack loader (a postLoader I think) ?
I'm not a webpack expert but I think it could do the job and keep your sources clean :metal: