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

Unmatched requests get logged to the console. #69

Closed
kentcdodds opened this issue Mar 19, 2020 · 6 comments
Closed

Unmatched requests get logged to the console. #69

kentcdodds opened this issue Mar 19, 2020 · 6 comments

Comments

@kentcdodds
Copy link
Contributor

The lib/index.js file is built via webpack and has a console.warn in it in the match function from node-match-path:

/**
 * Matches a given url against a path.
 */
const match = (path, url) => {
    const expression = path instanceof RegExp ? path : pathToRegExp(path);
    const match = expression.exec(url) || false;
    // Matches in strict mode: match string should equal to input (url)
    // Otherwise loose matches will be considered truthy:
    // match('/messages/:id', '/messages/123/users') // true
    const matches = !!match && match[0] === match.input;
    console.warn('nmp', { path, url, match, matches  })
    return {
        matches,
        params: match && matches ? match.groups || null : null,
    };
};

But no version of node-match-path has a console.warn in it. Could we get a rebuild of this and a publish to get rid of that warning? It's kind of distracting 😅

Thanks!

@kettanaito
Copy link
Member

Hello, @kentcdodds. Thanks for reporting this. My bad, I've published the library with some local version of node-match-path. Fixed in 0.9.1. Could you please update and let me know if it's fine? Sorry for any inconvenience this caused.

@kentcdodds
Copy link
Contributor Author

No worries. I'll take a look tomorrow. Thanks!

@kentcdodds
Copy link
Contributor Author

This is fixed. Thanks!

@bargar
Copy link

bargar commented Sep 15, 2020

For anybody arriving here like me wanting to log requests, you can use this technique:

rest.get('*', (req, res, ctx) => {
  console.log(req.url.href)
  // Notice no `return res()` statement
})

The lack of return means that other handlers can still serve the request after it is logged.

@kettanaito
Copy link
Member

Hey, @bargar! Thanks for posting this for others.

Note that MSW logs out requests that were matched, meaning their responses were mocked. However, you can see those requests and other requests in the "Network" tab of your browser. Sometimes extra logging to the console may not be necessary: just look into the "Network".

@bargar
Copy link

bargar commented Sep 15, 2020

Thanks for posting this for others.

My pleasure.

you can see those requests and other requests in the "Network" tab of your browser

An excellent point for msw in the browser!

I probably should have mentioned that I was coming from the context of debugging a react testing library test run at the command line. The request logging alerted me to an unexpected request that I had neglected to mock with msw.

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