Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better usage when mocking client #14

Open
ncuillery opened this issue Sep 22, 2015 · 2 comments
Open

Better usage when mocking client #14

ncuillery opened this issue Sep 22, 2015 · 2 comments

Comments

@ncuillery
Copy link

It's okay to write these two lines of code

var config = require('./superagent-mock-config'); 
require('superagent-mock')(request, config);

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 🤘

@fdubost
Copy link
Member

fdubost commented Sep 22, 2015

Good idea ! 👍

Feel free to make a PR 😉

@elisherer
Copy link
Contributor

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.

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

No branches or pull requests

3 participants