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

opt-out of logs? #111

Closed
kentcdodds opened this issue Apr 21, 2020 · 10 comments · Fixed by #113
Closed

opt-out of logs? #111

kentcdodds opened this issue Apr 21, 2020 · 10 comments · Fixed by #113

Comments

@kentcdodds
Copy link
Contributor

kentcdodds commented Apr 21, 2020

Is your feature request related to a problem? Please describe.

In my (edge) use case of having an app where we're pretending there really is a server even though there isn't. I'd prefer to not get anything logged to the console from MSW (unless there's an error).

Describe the solution you'd like

I'd like to be able to disable the logging. Perhaps as an option when I call start?

Describe alternatives you've considered

I'm considering overriding console.log/etc to filter out MSW logs.

Additional context

https://bookshelf.lol

@kettanaito
Copy link
Member

kettanaito commented Apr 22, 2020

I think this makes sense, the ability to opt-out of logs was voiced in the related ticket (), yet I've went with enabled by default.

Thinking out load, the arguments to the start() function may be adjusted as:

function start(options: StartOptions): Promise<ServiceWorkerRegistration| null>

interface StartOptions {
  serviceWorker: {
    url: string
    options: string
  }
  quiet: boolean
}

@kettanaito
Copy link
Member

It will be possible to opt out of logs in the next release (0.14.0):

import { composeMocks } from 'msw'

const { start } = composeMocks(...)
start({ quiet: true })

@kentcdodds
Copy link
Contributor Author

Awesome! Thank you :)

@kettanaito
Copy link
Member

@kentcdodds, could you please update to 0.14.0 and let me know that using the quiet: true option does what you need?

As always, there's an integrity bump ;) This release contains a bunch of other fixes, one of which affects the Service Worker module.

@kentcdodds
Copy link
Contributor Author

Just tried and running npx msw init public doesn't update my service worker 😬

@kentcdodds
Copy link
Contributor Author

Also, just noticed that this doesn't silence the first log that says [MSW] Mocking enabled.

I think I'd like all logs gone.

@kentcdodds
Copy link
Contributor Author

Oh, and I think the docs here need to be updated: https://redd.gitbook.io/msw/recipes/custom-service-worker-url :)

@kettanaito
Copy link
Member

Originally, I wanted to leave the activation message intact, so it's always evident the page is handled by the mock service worker. However, since the quiet mode is explicit, I believe there's little harm done in silencing the activation message as well. I'll provide a pull request in a short notice.

Just tried and running npx msw init public doesn't update my service worker.

What version of msw are you using? (npm ls msw).

@kettanaito
Copy link
Member

The activation message should now be silenced as well when using start({ quiet: true }).

Could you please update to 0.14.1 and let me know?

@kentcdodds
Copy link
Contributor Author

0.14.1 works! Thanks!

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

Successfully merging a pull request may close this issue.

2 participants