-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(test): Refactor Node integration tests to prevent nock leaks. #5579
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the README with these details?
IMO not the end of the world for us to have this explicit passing of server and scope. If we think it's too messy, we could also choose to create a class that manages this, and then have the url/server/scope be internal vars to that class. What do you think about that?
If we choose to do the class method, let's first merge this in to unblock Tim, and then come back to it.
@@ -19,6 +19,7 @@ | |||
"@remix-run/dev": "^1.6.5", | |||
"@types/react": "^17.0.47", | |||
"@types/react-dom": "^17.0.17", | |||
"nock": "^13.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did we have to add this dep?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS falls back to the global installation of nock
, which seems to have a slight difference between what we use in node-integration-tests
. Had to add this (the same version with node-integration-tests
) to resolve it.
count: number, | ||
method: 'get' | 'post' = 'get', | ||
endServer: boolean = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that there are three options, can we pass this in as an options obj (2nd arg)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Yes, I think it would make it much cleaner and easier/safer to use. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for taking a look at this @onurtemizkan!
Currently, Node integration tests initialize nock interceptors on server initialization and end them after a certain timeout. This recently created problems with asynchronous event processors, and caused random cases of envelope leaks between tests.
To resolve it, this approach returns
http.Server
andnock.Scope
instances back to the test, to eventually be provided to a helper that either collects envelopes or makes requests. The responsibility of ending those two instances is moved to the collection helpers likegetEnvelopeRequest
orgetAPIResponse
.Tests that do not use those helpers should close the server and nock interceptors manually.
This way, we ensure that we do not lose the context of the server and the nock interceptors between tests.
Needs to be tested on #5512