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(perf): explore happy-dom (highly wip) #16713

Closed

Conversation

belgattitude
Copy link
Contributor

@belgattitude belgattitude commented May 14, 2023

caution Highly WIP and I'm not sure I would do this, but it might be a good case to help the upstream https://github.com/capricorn86/happy-dom to fill gaps and bring more supported features.

Part of ci performance explorations.

Install

yarn install
yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache
cd packages/core/admin

# Works
yarn test:front --coverage false --env=@happy-dom/jest-environment

Benchmarks.

The test suite won't run with the latest version of happy-dom. I'll comment failing issues. Not sure about speed but I would say between 5-20% speedup. Not sure it's worth it due to happy-dom parity (cost/benefit). Will try to reach the author.

What works right now

yarn test:front --coverage false \
        --testPathPattern "admin/src/utils/*" \
        --env=@happy-dom/jest-environment

# compared to

yarn test:front --coverage false \
        --testPathPattern "admin/src/utils/*" \
        --env=jsdom

Not enough passing tests to measure

@belgattitude
Copy link
Contributor Author

Happy dom upstream issue

yarn install
yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache
cd packages/core/admin
yarn test:front --coverage false --testPathPattern admin/src/components --env @happy-dom/jest-environment
   TypeError: Cannot read properties of undefined (reading 'matches')

      12 |
      13 | const getDefaultTheme = () => {
    > 14 |   const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';

@belgattitude
Copy link
Contributor Author

belgattitude commented May 14, 2023

Happy dom upstream issue

Test failing example: https://github.com/strapi/strapi/blob/main/packages/core/admin/admin/src/pages/NotFoundPage/tests/index.test.js#L27

yarn install
yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache
cd packages/core/admin
yarn test:front --coverage false --testPathPattern admin/src/pages --env @happy-dom/jest-environment

image

@belgattitude
Copy link
Contributor Author

belgattitude commented May 14, 2023

@capricorn86 Would you be interested to collaborate on this attempt ?

I'm not working for strapi, but got a recent interest in whatever helps to reduce carbon emission 🌳 . Very naive and tiny effect I guess but I need to start somewhere, before sharing more (a future website with recipes and collection of libraries)

Strapi seemed to me a very good start, cause I'm impressed by what they're doing as well as your work on happy-dom.

If you're interested let me know

@gu-stav
Copy link
Contributor

gu-stav commented May 15, 2023

@belgattitude Thank you again so much for investing all your time into our tooling :) I will be honest with you here: unless this would bring a significant speed improvement (which I doubt), I think I'd like to stick to the default jest setup. The system is already complex (and brittle) enough and I would prefer to stick to the default jsdom setup for now.

While it is a novel goal to optimize for carbon emissions looking at the high-level setup will help to not micro-optimize steps, but improve the situation as a whole. You have already had a tremendous impact for us, which I appreciate a lot.

@belgattitude
Copy link
Contributor Author

Makes sense

@gu-stav gu-stav closed this May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants