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

Tests: mock fetch in PermissionsCheck tests #3958

Merged
merged 2 commits into from
Jul 16, 2024
Merged

Tests: mock fetch in PermissionsCheck tests #3958

merged 2 commits into from
Jul 16, 2024

Conversation

katspaugh
Copy link
Member

What it solves

The PermissionsCheck tests were doing actual fetch requests to a gas oracle which sometimes failed on CI. Fetch is now mocked to return an empty object.

Copy link

github-actions bot commented Jul 16, 2024

Copy link

github-actions bot commented Jul 16, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

github-actions bot commented Jul 16, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 79.02% 11614/14697
🔴 Branches 58.64% 2853/4865
🟡 Functions 65.94% 1855/2813
🟢 Lines 80.41% 10472/13023

Test suite run success

1436 tests passing in 198 suites.

Report generated by 🧪jest coverage report action from 63263a3

Copy link

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1012.87 KB (-10 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Comment on lines +22 to +30
Object.defineProperty(window, 'fetch', {
writable: true,
value: jest.fn(() =>
Promise.resolve({
ok: false,
json: () => Promise.resolve({}),
}),
),
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know which call ends up doing the fetch? Imo we shouldn't mock fetch but instead mock our own functions that wrap the fetch calls. It seems we are overwriting the global object, do you know if this is cleaned up after the tests run?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the same type of mock in the GasPrice tests and it seems to be fine.

@katspaugh katspaugh merged commit 7df9a1b into dev Jul 16, 2024
14 checks passed
@katspaugh katspaugh deleted the fix-tests branch July 16, 2024 13:54
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants