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

fix: support userAgent option for jsdom environment #11773

Merged
merged 6 commits into from Aug 23, 2021
Merged

fix: support userAgent option for jsdom environment #11773

merged 6 commits into from Aug 23, 2021

Conversation

nwalters512
Copy link
Contributor

@nwalters512 nwalters512 commented Aug 20, 2021

Summary

In older versions of jsdom, it was possible to specify a custom userAgent in the JSDOM constructor options. In Jest, that could be set with testEnvironmentOptions, 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, the userAgent 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 set userAgent in testEnvironmentOptions, 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.

@facebook-github-bot
Copy link
Contributor

Hi @nwalters512!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@nwalters512
Copy link
Contributor Author

Just signed the CLA 📝

@nwalters512 nwalters512 marked this pull request as ready for review August 20, 2021 23:44
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Contributor

@sigveio sigveio left a 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 🙂

@nwalters512
Copy link
Contributor Author

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-commenter
Copy link

Codecov Report

Merging #11773 (953ca86) into master (84b3b03) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
packages/jest-environment-jsdom/src/index.ts 41.81% <100.00%> (+2.19%) ⬆️
packages/expect/src/utils.ts 95.58% <0.00%> (-0.56%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84b3b03...953ca86. Read the comment docs.

Copy link
Member

@SimenB SimenB left a 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 🙂

@SimenB SimenB changed the title feat: support userAgent option for jsdom environment fix: support userAgent option for jsdom environment Aug 23, 2021
@SimenB SimenB merged commit 4f4062b into jestjs:master Aug 23, 2021
@nwalters512
Copy link
Contributor Author

🙌 thanks for getting this merged quickly and fixing up my lint errors - apologies, I missed those locally!

@nwalters512 nwalters512 deleted the feat/jsdom-support-user-agent branch August 23, 2021 18:31
splincode pushed a commit to splincode/jest that referenced this pull request Aug 24, 2021
@SimenB
Copy link
Member

SimenB commented Aug 24, 2021

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

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants