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

jest environment update #2940

Conversation

andreibereczki
Copy link

@andreibereczki andreibereczki commented Jan 22, 2025

Summary

With both angular & cdk on v19 there are several issues when running jest unit tests. For more details, please see linked inssue.
Since the jest maintainers refuse to upgrade the jsdom dependency in their published jest environment due to several breaking changes (see #15417, #14891, #14846 & more), i have created a custom jest environment with the latest jsdom package as dependency.

It would be great if jest-preset-angular could support [email protected] out of the box using this package.

Test plan

CI?

Does this PR introduce a breaking change?

  • Yes
  • No

Breaking changes are mostly related to how jsdom defines the location object. They are more strictly adhering to the latest standard specification, and as such, the location object is not writeable anymore.
Several workarrounds exist. A quick google should yield results.

Other information

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 22, 2025

Hi,

Thank you for the effort 😀. I think that might be the same as this https://thymikee.github.io/jest-preset-angular/docs/guides/jsdom-version which was introduced in 14.5

Besides, jest-preset-angular doesn’t have plan to release a breaking change version soon since there are other things to work on too

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 22, 2025

And to make the custom environment solution stand out, we can combine this doc https://thymikee.github.io/jest-preset-angular/docs/guides/jsdom-version/ and this doc https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment into single doc which explains how to set up a test environment for Angular using jsdom and potentially happy-dom as well

@andreibereczki
Copy link
Author

andreibereczki commented Jan 22, 2025

Hi,

Thank you for the effort 😀. I think that might be the same as this https://thymikee.github.io/jest-preset-angular/docs/guides/jsdom-version which was introduced in 14.5

Besides, jest-preset-angular doesn’t have plan to release a breaking change version soon since there are other things to work on too

Hello @ahnpnl ,

the documentation you linked is a bit confusing. If jest-preset-angular/environments/jsdom is supposed to:

  • be an example, then overwriting it in the user's jest config is trivial
  • exist and is supposed to be a generic way of using a particular version of jsdom installed by the user, then this doesn't work.

However, if we are in the first scenarion, although overwriting the testEnvironment configuration option is trivial, it would be that much better (no headaches, no research necessary, etc) for jest-preset-angular to deliver this out of the box.

I understand the desire of not releasing breaking changes, however, in this case, i strongly believe that the benefits outweigh the downsides.
And as a second argument: these changes are breaking in the sense that they disallow certain code that should not have been allowed in the first place (Object.defineProperty(window, 'location', { ... }) or straight up assignment: window.location = { ... }).

Is there a scenario where you would consider merging this? If yes, could you give a few details?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 22, 2025

Indeed I notice the doc is a bit confusing, in general jest-preset-angular/environments/jsdom is the custom implementation of jest-environment-jsdom like your package to support other versions of jsdom

We just need to make the doc clearer as 14.5 already deliver OOTB solution like your package

@andreibereczki
Copy link
Author

Indeed I notice the doc is a bit confusing, in general jest-preset-angular/environments/jsdom is the custom implementation of jest-environment-jsdom like your package to support other versions of jsdom

Then i personally couldn't get it to work.

Can you please detail how to do that?
The latest jest-preset-angular does not contain anything like jest-preset-angular/environments/jsdom.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 22, 2025

Ah sorry for the wrong path, it should be jest-preset-angular/environments/jest-jsdom-env, I'm updating the doc here #2941

About combining doc for test environment, that will be for another PR 😃

@andreibereczki
Copy link
Author

Cool! I can confirm that the path you provded works.

Also jest-preset-angular has a [email protected] peer dependency, so it achieves exactly what my PR does.
I will close the PR.

@andreibereczki andreibereczki deleted the feature/jest-environment-update branch January 22, 2025 09:44
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.

2 participants