Skip to content

feat: support JSDOM 27 for @jest/environment-jsdom-abstract - #15834

Merged
cpojer merged 1 commit into
jestjs:mainfrom
ahnpnl:copilot/fix-10
Sep 23, 2025
Merged

cpojer merged 1 commit into
jestjs:mainfrom
ahnpnl:copilot/fix-10

Conversation

@ahnpnl

@ahnpnl ahnpnl commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

Summary

Add changes to support JSDOM 27 for @jest/environment-jsdom-abstract

Test plan

Added new e2e tests to cover the change

@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 22, 2025 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ahnpnl / name: Ahn (05da954)

@netlify

netlify Bot commented Sep 22, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 05da954
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/68d14b7ceccfa60008409aab
😎 Deploy Preview https://deploy-preview-15834--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Sep 22, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15834

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15834

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15834

create-jest

npm i https://pkg.pr.new/create-jest@15834

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15834

expect

npm i https://pkg.pr.new/expect@15834

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15834

jest

npm i https://pkg.pr.new/jest@15834

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15834

jest-circus

npm i https://pkg.pr.new/jest-circus@15834

jest-cli

npm i https://pkg.pr.new/jest-cli@15834

jest-config

npm i https://pkg.pr.new/jest-config@15834

@jest/console

npm i https://pkg.pr.new/@jest/console@15834

@jest/core

npm i https://pkg.pr.new/@jest/core@15834

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15834

jest-diff

npm i https://pkg.pr.new/jest-diff@15834

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15834

jest-each

npm i https://pkg.pr.new/jest-each@15834

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15834

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15834

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15834

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15834

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15834

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15834

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15834

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15834

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15834

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15834

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15834

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15834

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15834

jest-mock

npm i https://pkg.pr.new/jest-mock@15834

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15834

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15834

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15834

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15834

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15834

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15834

jest-runner

npm i https://pkg.pr.new/jest-runner@15834

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15834

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15834

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15834

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15834

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15834

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15834

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15834

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15834

@jest/types

npm i https://pkg.pr.new/@jest/types@15834

jest-util

npm i https://pkg.pr.new/jest-util@15834

jest-validate

npm i https://pkg.pr.new/jest-validate@15834

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15834

jest-worker

npm i https://pkg.pr.new/jest-worker@15834

pretty-format

npm i https://pkg.pr.new/pretty-format@15834

commit: 05da954

@ahnpnl
ahnpnl force-pushed the copilot/fix-10 branch 8 times, most recently from a6b0150 to 1b6a313 Compare September 22, 2025 12:56
@ahnpnl
ahnpnl marked this pull request as ready for review September 22, 2025 13:37
@ahnpnl

ahnpnl commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

hi @cpojer @SimenB would you please help to review? Thank you :)

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@htho

htho commented Oct 1, 2025

Copy link
Copy Markdown

Hi,

I think I am lacking some jest concepts, because I have no Idea on how to configure jest to use jsdom v27.
Looking at your changes and the sparse documentation on customExportConditions I came up with:

/**
 * @jest-environment jsdom
 * @jest-environment-options {"customExportConditions": ["browser"]}
 */

describe("style", () => {
    it("treats undefined empty string", () => {
        const p = document.createElement("p");
        p.style.boxShadow = undefined as unknown as string;
        expect(p.style.boxShadow).toBe(""); // works in jsdom@27, but not in v26
    });
});
{
  "type": "module",
  "scripts": {
    "test": "jest"
  },
  "devDependencies": {
    "@babel/preset-env": "^7.28.3",
    "@babel/preset-typescript": "^7.27.1",
    "@types/jest": "^30.0.0",
    "jest": "^30.2.0",
    "jest-environment-jsdom": "^30.2.0",
    "jsdom": "^27.0.0",
    "typescript": "^5.9.3"
  }
}

Could you please clarify this in the documentation?

@ahnpnl

ahnpnl commented Oct 1, 2025 •

Copy link
Copy Markdown
Contributor Author

Hi @htho I think the doc isn't clear and not updated with concrete example. I put the example how to do it in code wise here https://github.com/jestjs/jest/tree/main/e2e/custom-jsdom-version/v27

Thought technically, it should work with jest-environment-jsdom OOTB

@ahnpnl

ahnpnl commented Oct 1, 2025

Copy link
Copy Markdown
Contributor Author

I just checked jest-environment-jsdom package

it only accepts JSDOM 26, which means you need to create a custom environment to use JSDOM 27 as https://github.com/jestjs/jest/tree/main/e2e/custom-jsdom-version/v27 demonstrates

@htho

htho commented Oct 1, 2025

Copy link
Copy Markdown

Thank you @ahnpnl
It works for me.

I suppose we don't default to JSDOM 27 to not break any existing tests?

While the custom-jsdom-env.js approach works, the documentation suggests something else, but is completely misleading. Whats the point of customExportCondtions?
What am I supposed to put in the exports field in the package.json?

Both jest-environment-jsdom and jest-environment-node allow specifying customExportConditions, which allow you to control which versions of a library are loaded from exports in package.json. jest-environment-jsdom defaults to ['browser']. jest-environment-node defaults to ['node', 'node-addons'].

@ahnpnl

ahnpnl commented Oct 1, 2025

Copy link
Copy Markdown
Contributor Author

I suppose we don't default to JSDOM 27 to not break any existing tests?

Yes, this is a breaking change

While the custom-jsdom-env.js approach works, the documentation suggests something else, but is completely misleading. Whats the point of customExportCondtions?

I checked https://www.npmjs.com/package/jest-environment-jsdom?activeTab=code and jest-environment-jsdom doesn't have export condition for browser so I'm not sure why the doc mentioned like that.

What am I supposed to put in the exports field in the package.json?

I think the supporting for custom export condition is there, just the doc seems to be not clear about example. I would imagine something like

// node_modules/<your_custom_jsdom_env_npm_name>/package.json
{
    //...
    "browser": "./index.js",
    "exports": {
          ".": {
              //...
             "browser": {
                   "import": "./index.mjs",
                   "default": "./index.js"
             },
    },
}

I think the doc mentioned about custom export condition only applies to custom environment npm packages, not your project root package.json

@htho

htho commented Oct 1, 2025

Copy link
Copy Markdown

Thank you for your time.
Is there anyone we can mention here to clarify the documentation?

@ahnpnl

ahnpnl commented Oct 1, 2025

Copy link
Copy Markdown
Contributor Author

Normally I just create PR to update the doc and let maintainers review 😆

@htho

htho commented Oct 8, 2025

Copy link
Copy Markdown

@ahnpnl I'm sorry to bother you, but you seem to have some knowledge about @jest/environment-jsdom-abstract.
Do you have any Idea why my approach to use a Proxy in a custom JSDOM environment does not work?
https://stackoverflow.com/questions/79784243/mock-jsdom-location-using-jest-environment-jsdom-abstract

@SimenB

SimenB commented Oct 8, 2025 •

Copy link
Copy Markdown
Member

Please don't use the issue tracker as a support forum.

If the docs are unclear, please open up an issue about that (or even better, a PR to clarify)

@github-actions

github-actions Bot commented Nov 8, 2025

Copy link
Copy Markdown

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 Nov 8, 2025
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.

4 participants