mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
15.91k stars 517 forks source link

Vitest Remix testing warnings of missed file system requests and Network Error logs #1630

Closed ericchernuka closed 9 months ago

ericchernuka commented 1 year ago

Prerequisites

Environment check

Node.js version

18.16.0

Reproduction repository

https://github.com/ericchernuka/examples-new/blob/repro-vitest-msw-warnings/examples

Reproduction steps

I've set up the examples-new repo with-remix so that it mimics a lot of what we've seen lately at my organization. Running the pnpm test within examples/with-remix will throw errors related to paths that don't seem related to my tests.

Current behavior

I noticed this happened when I made this line, https://github.com/ericchernuka/examples-new/blob/repro-vitest-msw-warnings/examples/with-remix/app/routes/_index.tsx#L33, use the json return type from Remix rather than just an object like it is in the original repo. Removing json should pass without errors, but with json, it throws errors.

This also includes the unstable_createRemixStub from @remix/testing, which from the source doesn't seem to do anything other than wire up so that it'll mimic Remix.

I also had similar errors with Kent's rocket-rentals repo, https://github.com/epicweb-dev/rocket-rental/issues/17, where I saw file system items being logged.

I'm bringing this up as I've noticed that CPU/memory seem too high that I have to force quit node after running test tests in watch mode, so I wasn't entirely sure if something causing these additional warnings was further making the test runner unresponsive.

Lastly, when we switched to happy-dom many of the errors seem to go away, but if the test had an error in it, it wasn't typical Vitest errors and instead the ones this repo seemed to be showing which makes testing quite hard.

Expected behavior

kettanaito commented 11 months ago

It's a bit difficult to reason about what requests are meant as your app's network and what are the implementation detail of your framework. I think what MSW can do is ignore requests with the node_modules in the request URL by default. Even that isn't a reliable strategy as it potentially collides with a regular request containing that phrase.

kettanaito commented 9 months ago

MSW will ignore file:// requests when warning you about unhandled requests. Implemented in #1997.

kettanaito commented 9 months ago

Released: v2.1.5 🎉

This has been released in v2.1.5!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.