-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix: support userAgent option for jsdom environment #11773
fix: support userAgent option for jsdom environment #11773
Conversation
Hi @nwalters512! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Just signed the CLA 📝 |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A changelog entry appears to be missing 🙂
Thanks for the reminder! I was waiting until the PR was open so I could grab the link to it. Should be all set now 🙂 |
Codecov Report
@@ Coverage Diff @@
## master #11773 +/- ##
==========================================
- Coverage 69.01% 69.01% -0.01%
==========================================
Files 312 312
Lines 16339 16341 +2
Branches 4736 4738 +2
==========================================
+ Hits 11276 11277 +1
- Misses 5035 5036 +1
Partials 28 28
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think this is a bug fix as you say 🙂
🙌 thanks for getting this merged quickly and fixing up my lint errors - apologies, I missed those locally! |
No problem, thanks for taking the time to send a PR 🙂 CI was supposed to tell you about the lint stuff, but since GH doesn't run actions for first time contributors without a maintainer hitting the button it never happened |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
In older versions of
jsdom
, it was possible to specify a customuserAgent
in the JSDOM constructor options. In Jest, that could be set withtestEnvironmentOptions
, which would be passed as options to the Jest constructor. The Jest docs even specifically call out this example: https://github.com/facebook/jest/blame/6df4ad4a8eb4f63fa4580d6f5664f43762940379/docs/Configuration.md#L1132.However,
jsdom
removed this option at some point in a minor release of v12 in this commit. When we went to upgrade Jest to a newer version, many of our tests started failing because jsdom's default user agent was being used instead of the one we had specified.As called out in this comment, it's possible to work around this by setting up a custom testing environment, but I'd hate to have to copy that boilerplate around to all of the repos where we need to customize the user agent. So, I'm proposing this change.
This change should be safe; for the past several major versions of
jsdom
, theuserAgent
option to the constructor has been a no-op, so this should be considered a feature addition as opposed to a breaking change. If someone had previously setuserAgent
intestEnvironmentOptions
, it would start taking effect with this change where it hadn't previously; that's the only risk to this I can think of.Test plan
I edited the code in
node_modules
in my project to reflect these changes, and it worked as expected! I also added a test case, which passes.