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 jest #15642

Merged
merged 2 commits into from
Aug 23, 2022
Merged

upgrade jest #15642

merged 2 commits into from
Aug 23, 2022

Conversation

brad-decker
Copy link
Contributor

@brad-decker brad-decker commented Aug 18, 2022

Explanation

Fixes issue related to slack reports of unit tests consuming upwards of more than 20gb of memory and 4gb of swap. Note that this PR does nothing to fix the underlying memory leaks in our tests and that should be explored separately. This works around the memory issue by forcing worker processes to terminate once they've consumed 500mb of memory. I chose 500mb because our ci environment has 4gb of ram and we run two workers when running tests in jest. This would allow us to theoretically add another 6 workers without running into out of memory issues. I'll test that theory in another PR aimed at improving CI.

Consequences of this PR:

  1. The default environment for tests is node, so had to install the jsdom environment and specify jsdom as our testEnvironment in jest.config.js. This can be changed per file.
  2. Had to temporarily disable the button.stories.test.js file because it eventually imports a .mdx file and the transform that was previously working for 'mdx' files in jest no longer works.
  3. Had to patch the types for jsdom to not use the import { type TypeName} syntax
  4. Removed the yargs patch because the newest version checks for the existence of Error.createErrorBoundary before calling it.
  5. Some minor syntax changes

Pre-Merge Checklist

  • PR template is filled out
  • IF this PR fixes a bug, a test that would have caught the bug has been added
  • PR is linked to the appropriate GitHub issue
  • PR has been added to the appropriate release Milestone

+ If there are functional changes:

  • Manual testing complete & passed
  • "Extension QA Board" label has been applied

@brad-decker brad-decker marked this pull request as ready for review August 18, 2022 22:35
@brad-decker brad-decker requested a review from a team as a code owner August 18, 2022 22:35
@metamaskbot
Copy link
Collaborator

Builds ready [d5eefb4]
Page Load Metrics (1847 ± 60 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint971871225381183
domContentLoaded16432032183712460
load16432032184712560
domInteractive16432032183712460

tmashuang
tmashuang previously approved these changes Aug 23, 2022
Copy link
Contributor

@tmashuang tmashuang left a comment

Choose a reason for hiding this comment

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

LGTM, will re-approve once the merge conflicts are resolved.

@metamaskbot
Copy link
Collaborator

Builds ready [7ede140]
Page Load Metrics (1826 ± 76 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint982181252612
domContentLoaded16192249179414771
load16192269182615776
domInteractive16192249179414771

tmashuang
tmashuang previously approved these changes Aug 23, 2022
Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

As per our slack conversation I think we can probably remove the ui/components/ui/button/button.stories.skippedtest.js file altogether

ui/components/ui/button/button.stories.skippedtest.js Outdated Show resolved Hide resolved
Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [206510f]
Page Load Metrics (2182 ± 137 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1072331271475228
domContentLoaded171626202163288138
load174126202182286137
domInteractive171626202163288138

// installed in @metamask/controllers so I had to just blanket specify all
// of the @metamask/controllers folder.
transformIgnorePatterns: [
'/node_modules/(?!(multiformats|uuid|nanoid|@metamask/controllers|@metamask/snap-controllers)/)',
Copy link
Contributor

Choose a reason for hiding this comment

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

multiformats, uuid, and nanoid makes sense, because they have recently(ish) converted to ESM, and I've seen Jest choke on these packages in other projects.

We don't ship ESM code in @metamask/controllers or @metamask/snap-controllers, however, so why did we have to list these here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

some of the dependencies nested inside the metamask/controllers repo are ESM and i could not figure out how to specify that recursion in this ignore pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see. Interesting...

+++ b/node_modules/@types/jsdom/node_modules/parse5/dist/index.d.ts
@@ -1,10 +1,10 @@
-import { type ParserOptions } from './parser/index.js';
+import { ParserOptions } from './parser/index.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry why do we have to remove type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

running tsc throws errors for using type keyword inside the brackets. You can import types and non types without specifying a keyword

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh... wow. That's subtle. How do other people even use this package then 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no idea. unless it has something to do with our setup.

@mcmire
Copy link
Contributor

mcmire commented Aug 23, 2022

Had to do a bit of research on this one. Looks like the next version of Jest includes workerIdleMemoryLimit, and that version isn't out yet, so this PR bumps it to 29.alpha. The docs for this option link to this issue which explains where it came from. It also might be worth following this PR to see if that fixes things further. Or this issue in Node.

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

@brad-decker
Copy link
Contributor Author

@mcmire my apologies for not posting more details in the description. You ended up doing some double work that I could have possibly saved some time for you if I would have simply transcribed @Gudahtt and I's thread in the extension channel into the PR description. I'll do better in the future.

@brad-decker brad-decker merged commit 0d862d4 into develop Aug 23, 2022
@brad-decker brad-decker deleted the upgrade-jest branch August 23, 2022 20:13
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2022
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.

5 participants