-
-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Mock all network requests #1499
Conversation
3a49dab
to
fba30a2
Compare
Mocking JSON-RPC requests in tests is somewhat inconvenient due to needing to spell out the full path for an Infura endpoint and specify full JSON-RPC request and response objects, but to make this easier, we've written a small wrapper around Nock. Currently we use this in one test within the `network-controller` package, but we plan to use this in a different package, so this commit extracts the class responsible for doing this. This also makes a small improvement to the API and adds a function that makes the class even easier to use.
By default HTTP requests are allowed to be made in tests. Because requests are not guaranteed to succeed, this can cause intermittently failing CI builds, forcing engineers to wait until PRs are ready to merge. This commit addresses this problem by enabling Nock globally and then modifying each test that hits the network to create proper mocks. This was somewhat difficult to do with the assets controller tests as they involve interactions with smart contracts on Mainnet. Also, Nock was upgraded to 13.3.x, as without this change, `nock.recorder`, used for debugging, was not working correctly.
fba30a2
to
b14bfda
Compare
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring: Next stepsTake a deeper look at the dependencyTake a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev. Remove the packageIf you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency. Mark a package as acceptable riskTo ignore an alert, reply with a comment starting with |
|
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.
Very nice improvement! Looks great.
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.
LGTM!
By default HTTP requests are allowed to be made in tests. Because requests are not guaranteed to succeed, this can cause intermittently failing CI builds, forcing engineers to wait until PRs are ready to merge. This commit addresses this problem by enabling Nock globally and then modifying each test that hits the network to create proper mocks. This was somewhat difficult to do with the assets controller tests as they involve interactions with smart contracts on Mainnet. Also, Nock was upgraded to 13.3.x, as without this change, `nock.recorder`, used for debugging, was not working correctly.
By default HTTP requests are allowed to be made in tests. Because requests are not guaranteed to succeed, this can cause intermittently failing CI builds, forcing engineers to wait until PRs are ready to merge. This commit addresses this problem by enabling Nock globally and then modifying each test that hits the network to create proper mocks. This was somewhat difficult to do with the assets controller tests as they involve interactions with smart contracts on Mainnet. Also, Nock was upgraded to 13.3.x, as without this change, `nock.recorder`, used for debugging, was not working correctly.
Explanation
By default HTTP requests are allowed to be made in tests. Because
requests are not guaranteed to succeed, this can cause intermittently
failing CI builds, forcing engineers to wait until PRs are ready to
merge.
This commit addresses this problem by enabling Nock globally and then
modifying each test that hits the network to create proper mocks. This
was somewhat difficult to do with the assets controller tests as they
involve interactions with smart contracts on Mainnet.
Also, Nock was upgraded to 13.3.x, as without this change,
nock.recorder
, used for debugging, was not working correctly.References
Fixes #1
Fixes #770.
Fixes #769
Fixes #771
Fixes #773
Changelog
(N/A)
Checklist