jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.12k stars 6.44k forks source link

[Feature]: Upgrade jest-environment-jsdom from v22 to v24 to avoid deprecated punycode warning #15148

Closed jschaf closed 3 months ago

jschaf commented 3 months ago

🚀 Feature Proposal

Upgrade jsdom to v24 from v22.

The current chain of dependencies from jest-environment-jsdom import punycode. As of Node 21, requiring punycode emits a deprecation warning.

The dependency chain is:

tough-cookie replaced psl with tldts in https://github.com/salesforce/tough-cookie/pull/346, avoiding the deprecation warning.

Motivation

Every test with jsdom logs a deprecation warning:

(node:15100) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:337:10)
    at loadBuiltinModule (node:internal/modules/helpers:104:7)
    at Function.Module._load (node:internal/modules/cjs/loader:999:17)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/opt/p/simc/node_modules/psl/index.js:5:16)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1426:10)

Example

Should be no change excepting breaking changes in jsdom.

Pitch

Because jest already imports jsdom.

opyate commented 3 months ago

Here's one more DeprecationWarning stack, in case it sheds more light.

> NODE_OPTIONS='--trace-deprecation' jest src/server/views/__tests__/login.njk.test.ts

(node:479351) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:397:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:333:10)
    at loadBuiltinModule (node:internal/modules/helpers:101:7)
    at Function.Module._load (node:internal/modules/cjs/loader:1006:17)
    at Module.require (node:internal/modules/cjs/loader:1237:19)
    at require (node:internal/modules/helpers:176:18)
    at Runtime._requireCoreModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1543:12)
    at Runtime.requireModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:840:19)
    at Runtime.requireModuleOrMock (/path-to-my-app/node_modules/jest-runtime/build/index.js:1048:21)
    at Object.<anonymous> (/path-to-my-app/node_modules/psl/index.js:5:16)
    at Runtime._execModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:882:12)
    at Runtime.requireModuleOrMock (/path-to-my-app/node_modules/jest-runtime/build/index.js:1048:21)
    at Object.<anonymous> (/path-to-my-app/node_modules/tough-cookie/lib/pubsuffix-psl.js:32:13)
    at Runtime._execModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:882:12)
    at Runtime.requireModuleOrMock (/path-to-my-app/node_modules/jest-runtime/build/index.js:1048:21)
    at Object.<anonymous> (/path-to-my-app/node_modules/tough-cookie/lib/cookie.js:34:19)
    at Runtime._execModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:882:12)
    at Runtime.requireModuleOrMock (/path-to-my-app/node_modules/jest-runtime/build/index.js:1048:21)
    at Object.<anonymous> (/path-to-my-app/node_modules/jsdom/lib/api.js:5:21)
    at Runtime._execModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:882:12)
    at Runtime.requireModuleOrMock (/path-to-my-app/node_modules/jest-runtime/build/index.js:1048:21)
    at Object.<anonymous> (/path-to-my-app/src/server/views/__tests__/login.njk.test.ts:18:17)
    at Runtime._execModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/path-to-my-app/node_modules/jest-runtime/build/index.js:882:12)
    at jestAdapter (/path-to-my-app/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:77:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runTestInternal (/path-to-my-app/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/path-to-my-app/node_modules/jest-runner/build/runTest.js:444:34)
SimenB commented 3 months ago

Duplicate of https://github.com/jestjs/jest/pull/15089 et.al.

jschaf commented 3 months ago

Based on #14846, do you mean this is a won't fix until Jest drops support for Node 16?

jsdom has dropped node 16, which I intend to support in the next release. However, creating a custom env with whatever version of jsdom you like should be easier in jest 30 via https://github.com/jestjs/jest/pull/14717.

Node 16 reached end-of-life in September 2023.

For tracking puposes, I'd prefer to keep this open unless it's a wontfix since the linked PRs (https://github.com/jestjs/jest/pull/15089, https://github.com/jestjs/jest/pull/14846#issuecomment-1885785901, https://github.com/jestjs/jest/issues/14954#issuecomment-1988729969) are all closed.

SimenB commented 3 months ago

Correct, however I'll probably publish a package for v24 for those that don't need node 16

aaronzshey commented 2 months ago

Another reason that we should use jsdom 24 instead of 22 - jsdom 22 depends on abab and domexception, both of which are also deprecated!

github-actions[bot] commented 1 month ago

This issue 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.