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

Upgrade jsdom #31751

Merged
merged 9 commits into from Jul 6, 2023
Merged

Upgrade jsdom #31751

merged 9 commits into from Jul 6, 2023

Conversation

uladzimirdev
Copy link
Contributor

@uladzimirdev uladzimirdev commented Jun 21, 2023

Description

Upgrade allows to cut 1.5-2min from jest run.

jsdom lib had a perf problem with getComputedStyle method, which is used a lot with css in js solutions. The problem was addressed in JSDOM 22.1.0, but jest itself waits for the major upgrade to take it into account. The temporary proposed solution is to use yarn resolutions.

Latest jsdom made window not configurable, so even router libs have to provide a fake configurable window object to bypass it. Unfortunately we can't do it right now as we're using old version of react-router, which doesn't allow overriding window in browserHistory

Issues about no longer possible window manipulation in jsdom
jsdom/jsdom#3492
jsdom/jsdom#3492 (comment)
jestjs/jest#5124

The issue about perf investigation
jsdom/jsdom#3234

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 66.66% and project coverage change: +0.07 🎉

Comparison is base (7d01270) 74.15% compared to head (b24bc86) 74.23%.

❗ Current head b24bc86 differs from pull request most recent head 8f04789. Consider uploading reports for the commit 8f04789 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #31751      +/-   ##
==========================================
+ Coverage   74.15%   74.23%   +0.07%     
==========================================
  Files        2914     2911       -3     
  Lines      103970   103567     -403     
  Branches    12889    12868      -21     
==========================================
- Hits        77103    76882     -221     
+ Misses      21039    20857     -182     
  Partials     5828     5828              
Flag Coverage Δ
back-end 86.70% <ø> (-0.08%) ⬇️
front-end 60.34% <66.66%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
frontend/src/metabase/lib/dom.js 44.19% <0.00%> (-0.40%) ⬇️
...e/frontend/src/metabase-enterprise/auth/actions.ts 100.00% <100.00%> (ø)
frontend/src/metabase/auth/actions.ts 75.40% <100.00%> (ø)

... and 163 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@metabase-bot metabase-bot bot added the visual Run Percy visual testing label Jun 23, 2023
@github-actions
Copy link

github-actions bot commented Jun 23, 2023

Codenotify: Notifying subscribers in CODENOTIFY files for diff ed6cdc7...8f04789.

Notify File(s)
@alxnddr frontend/src/metabase/visualizations/visualizations/LinkViz/LinkViz.unit.spec.tsx
@ranquild frontend/src/metabase/auth/actions.ts
frontend/src/metabase/auth/components/Logout/Logout.unit.spec.tsx

@@ -92,11 +93,11 @@ export const logout = createAsyncThunk(
async (redirectUrl: string | undefined, { dispatch, rejectWithValue }) => {
try {
await deleteSession();
await dispatch(clearCurrentUser());
dispatch(clearCurrentUser());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

clearCurrentUser is sync

@uladzimirdev uladzimirdev requested a review from a team June 23, 2023 21:10
import { parse } from "metabase-lib/expressions/recursive-parser";

import { generateExpression } from "./generator";

const fuzz = process.env.MB_FUZZ ? describe : describe.skip;
const fuzz = process.env.MB_FUZZ ? describe : _.noop;
Copy link
Member

Choose a reason for hiding this comment

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

what's the reason behind this change? Changing from describe.something to _.noop looks questionable since that affects the test output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's simple, if you check any CI run and frontend action, you'll see
image

but with this change you'll see

image

Notice, there is no 70k of the skipped tests anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

love this change

Copy link
Member

@WiNloSt WiNloSt Jun 27, 2023

Choose a reason for hiding this comment

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

Does that help improve the test time as well (2186s -> 1652s)? that'll be another huge win.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WiNloSt I don't think it affects perf somehow, maybe runners were busy so the result was ~2k seconds, but overall with this jsdom upgrade we should have 1.7-1.8k seconds per run.

jest should definitely count those describe.skip, but to my mind it's just javascript, so 10s is more than enough to go through it

frontend/src/metabase/lib/dom.js Show resolved Hide resolved
@WiNloSt WiNloSt requested review from a team and removed request for a team June 26, 2023 10:13
Copy link
Contributor

@iethree iethree left a comment

Choose a reason for hiding this comment

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

works for me!

import { parse } from "metabase-lib/expressions/recursive-parser";

import { generateExpression } from "./generator";

const fuzz = process.env.MB_FUZZ ? describe : describe.skip;
const fuzz = process.env.MB_FUZZ ? describe : _.noop;
Copy link
Contributor

Choose a reason for hiding this comment

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

love this change

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't bother me that much, but I don't see these wrapper methods being all that useful when we just have to remember to use them instead of the window.location methods everyone already knows.

Does mocking the window.location methods directly not work with the new version of jsdom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

answered here

one more time: unfortunately with latest jsdom it's not possible to mock window properties anymore (at least ways I tried didn't help)

jsdom/jsdom#3492
jsdom/jsdom#3492 (comment)

@deploysentinel
Copy link

deploysentinel bot commented Jun 27, 2023

No failed tests 🎉

Copy link
Member

@WiNloSt WiNloSt left a comment

Choose a reason for hiding this comment

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

Great work!

Copy link
Contributor

@kamilmielnik kamilmielnik left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@uladzimirdev uladzimirdev enabled auto-merge (squash) July 6, 2023 20:26
@uladzimirdev uladzimirdev merged commit 8fa8350 into master Jul 6, 2023
94 of 96 checks passed
@uladzimirdev uladzimirdev deleted the upgrade-jsdom branch July 6, 2023 21:00
@uladzimirdev uladzimirdev added the backport Automatically create PR on current release branch on merge label Aug 1, 2023
github-actions bot pushed a commit that referenced this pull request Aug 1, 2023
jsdom lib had a perf problem with getComputedStyle method, which is used a lot with css in js solutions. The problem was addressed in JSDOM 22.1.0, but jest itself waits for the major upgrade to take it into account. The temporary proposed solution is to use yarn resolutions.
metabase-bot bot added a commit that referenced this pull request Aug 1, 2023
jsdom lib had a perf problem with getComputedStyle method, which is used a lot with css in js solutions. The problem was addressed in JSDOM 22.1.0, but jest itself waits for the major upgrade to take it into account. The temporary proposed solution is to use yarn resolutions.

Co-authored-by: Uladzimir Havenchyk <125459446+uladzimirdev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge visual Run Percy visual testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants