Random errors in the CI runs #2524
-
|
I have been hunting around for a solution for this problem and didn't find any, hence the post. We are using MSW to mock out responses. It is a react app, with vite and testing with vitest. We are using axios to make api calls. We find that tests at random fail in CI but we are unable to reproduce it locally. Even in CI it fails once in a while. I have tried a few things but this my setup right now - Inside setupTests.ts, I have this - My test file looks like this - In my CI I get an error as below I also have tried making my vitest config to say only one worker at a time like this - We still get these random errors. If I retrigger the build run it works fine. Does anything obvious standout? My hunch is another test is resetting the handlers before this test can complete. If so, how do I about debugging this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi, @Sethuraman. Afaik, it's a bad idea to nest The second mistake I've spotted in your code is that you're adding |
Beta Was this translation helpful? Give feedback.
Hi, @Sethuraman. Afaik, it's a bad idea to nest
before*andafter*hooks in utility functions. You're making it much harder for your testing framework to apply then. That's likely the root cause for this intermittence. Move them out on the root levelsetupTest.tsand instead reuse the sameserverinstance if you want a helper likemakeServer(). We are showcasing that setup in the Node.js integration in the docs.The second mistake I've spotted in your code is that you're adding
server.use()overrides afterrender(). By doing that, you are welcoming a race condition between your component rendering and MSW learning about your request handlers. Please add those overrides before your render …