diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a3c6889c13a..32f215270ba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - `[jest-config]` [**BREAKING**] Make `snapshotFormat` default to `escapeString: false` and `printBasicPrototype: false` ([#13036](https://github.com/facebook/jest/pull/13036)) +- `[jest-environment-jsdom]` [**BREAKING**] Upgrade to `jsdom@20` ([#13037](https://github.com/facebook/jest/pull/13037)) ### Fixes diff --git a/docs/UpgradingToJest29.md b/docs/UpgradingToJest29.md index a924b1a2d17e..4a1633aecc95 100644 --- a/docs/UpgradingToJest29.md +++ b/docs/UpgradingToJest29.md @@ -27,3 +27,7 @@ If you want to keep the old behavior, you can set the `snapshotFormat` property + printBasicPrototype: true + } ``` + +## JSDOM upgrade + +`jest-environment-jsdom` has upgraded `jsdom` from v19 to v20. Due to issues with `@types/jsdom`, if you extend this environment, you might run into type errors. See https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/60999#discussioncomment-3158685. diff --git a/packages/expect/tsconfig.json b/packages/expect/tsconfig.json index 5c132ec1e784..330ff26d00c9 100644 --- a/packages/expect/tsconfig.json +++ b/packages/expect/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "lib": ["es2020", "dom"], "rootDir": "src", "outDir": "build" }, diff --git a/packages/jest-environment-jsdom/package.json b/packages/jest-environment-jsdom/package.json index f7beb56fd63b..c2214819d97a 100644 --- a/packages/jest-environment-jsdom/package.json +++ b/packages/jest-environment-jsdom/package.json @@ -20,11 +20,10 @@ "@jest/environment": "^28.1.3", "@jest/fake-timers": "^28.1.3", "@jest/types": "^28.1.3", - "@types/jsdom": "^16.2.4", "@types/node": "*", "jest-mock": "^28.1.3", "jest-util": "^28.1.3", - "jsdom": "^19.0.0" + "jsdom": "^20.0.0" }, "devDependencies": { "@jest/test-utils": "^28.1.3" diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 7ae1345df4be..2412dc9b4652 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -5,7 +5,10 @@ * LICENSE file in the root directory of this source tree. */ +/// + import type {Context} from 'vm'; +// @ts-expect-error: TODO: we're missing v20 types import {JSDOM, ResourceLoader, VirtualConsole} from 'jsdom'; import type { EnvironmentContext, @@ -27,7 +30,8 @@ type Win = Window & }; export default class JSDOMEnvironment implements JestEnvironment { - dom: JSDOM | null; + // TODO: make non-privat when we have `@types/jsdom` again + private dom: JSDOM | null; fakeTimers: LegacyFakeTimers | null; fakeTimersModern: ModernFakeTimers | null; global: Win; @@ -40,6 +44,7 @@ export default class JSDOMEnvironment implements JestEnvironment { const virtualConsole = new VirtualConsole(); virtualConsole.sendTo(context.console, {omitJSDOMErrors: true}); + // @ts-expect-error: TODO: we're missing v20 types virtualConsole.on('jsdomError', error => { context.console.error(error); }); diff --git a/packages/jest-fake-timers/tsconfig.json b/packages/jest-fake-timers/tsconfig.json index 4a4b01562562..3c20004c2488 100644 --- a/packages/jest-fake-timers/tsconfig.json +++ b/packages/jest-fake-timers/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "lib": ["es2020", "dom"], "rootDir": "src", "outDir": "build" }, diff --git a/packages/jest-matcher-utils/tsconfig.json b/packages/jest-matcher-utils/tsconfig.json index b2323e702d75..3905821cea60 100644 --- a/packages/jest-matcher-utils/tsconfig.json +++ b/packages/jest-matcher-utils/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "lib": ["es2020", "dom"], "rootDir": "src", "outDir": "build" }, diff --git a/packages/jest-runtime/package.json b/packages/jest-runtime/package.json index e978068c8779..350a1d6a8550 100644 --- a/packages/jest-runtime/package.json +++ b/packages/jest-runtime/package.json @@ -24,6 +24,7 @@ "@jest/test-result": "^28.1.3", "@jest/transform": "^28.1.3", "@jest/types": "^28.1.3", + "@types/node": "*", "chalk": "^4.0.0", "cjs-module-lexer": "^1.0.0", "collect-v8-coverage": "^1.0.0", @@ -43,7 +44,6 @@ "@jest/test-utils": "^28.1.3", "@types/glob": "^7.1.1", "@types/graceful-fs": "^4.1.3", - "@types/node": "*", "jest-environment-node": "^28.1.3" }, "engines": { diff --git a/packages/pretty-format/src/__tests__/DOMCollection.test.ts b/packages/pretty-format/src/__tests__/DOMCollection.test.ts index 4a6ba61c894b..fa858e836ff5 100644 --- a/packages/pretty-format/src/__tests__/DOMCollection.test.ts +++ b/packages/pretty-format/src/__tests__/DOMCollection.test.ts @@ -126,7 +126,7 @@ describe('DOMCollection plugin for list items', () => { }); const expectedHTMLFormControlsCollection = [ - 'HTMLCollection [', + 'HTMLFormControlsCollection [', '