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

Test overriding isolation #407

Closed
yekver opened this issue Sep 29, 2020 · 6 comments
Closed

Test overriding isolation #407

yekver opened this issue Sep 29, 2020 · 6 comments
Labels
help wanted Extra attention is needed needs:discussion scope:node Related to MSW running in Node

Comments

@yekver
Copy link

yekver commented Sep 29, 2020

I use jest with puppeteer to run my e2e tests. If I run jest --maxWorkers=5 instead for jest --runInBand then I will probably face with a race condition problem when some test use request overriding and will affect all other tests, because it's not scoped only to this test.

Am I right?

@yekver yekver added the feature label Sep 29, 2020
@marcosvega91
Copy link
Member

Hi @yekver thanks for reaching us.

It could happen.

As we suggest the server instance should be one. If you add handlers in some tests they will be added to the same shared server instance. This will cause this kind of issues

@yekver
Copy link
Author

yekver commented Sep 30, 2020

Are there anything we can do to deal with this concurrency and make per-test overriding isolated?

Or this is by design and won't be fixed?

@marcosvega91
Copy link
Member

Call of setupServer performs patching of necessary modules (http/XMLHttpRequest). A possible solution is to run multiple instances, but is discouraged at the moment because of patching. I don't know what we can do for now to make it better.

@kettanaito
Copy link
Member

As @marcosvega91 has mentioned, request interception in NodeJS is achieved by patching request issuing modules. That patching is done for the entire process.

In that way MSW works almost identical to Nock. Would anybody be interested in looking how Nock handles this scenario? We can learn a thing of two from them.

@kettanaito kettanaito added help wanted Extra attention is needed needs:discussion question scope:node Related to MSW running in Node and removed feature labels Oct 28, 2020
@marcosvega91
Copy link
Member

I think that only http and https modules should have this problem. JSDOM for example should already handle multiple instances of window. What do you think if we try to patch http/XMLHttpRequest one time? If you call server.listen we can increment a counter and decrement on server.close. All mocks are restored only when counter is 0. In this way we can patch everything one time and multiple server instances could work together.

@kettanaito
Copy link
Member

Let's discuss this issue in #474. Thanks.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed needs:discussion scope:node Related to MSW running in Node
Projects
None yet
Development

No branches or pull requests

3 participants