diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d6ffb16d57e..473034f13934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -150,6 +150,7 @@ - `[expect]` Add type definitions for asymmetric `closeTo` matcher ([#12304](https://github.com/facebook/jest/pull/12304)) - `[jest-cli]` Load binary via exported API ([#12315](https://github.com/facebook/jest/pull/12315)) - `[jest-config]` Replace `jsonlint` with `parse-json` ([#12316](https://github.com/facebook/jest/pull/12316)) +- `[jest-environment-jsdom]` [**BREAKING**] Remove Node global `Buffer` ([#11241](https://github.com/facebook/jest/pull/11241)) - `[jest-repl]` Make module importable ([#12311](https://github.com/facebook/jest/pull/12311) & [#12315](https://github.com/facebook/jest/pull/12315)) ### Chore & Maintenance diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index f16e876ecefe..5a3c2dbbce52 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -76,9 +76,6 @@ export default class JSDOMEnvironment implements JestEnvironment { this.global.Error.stackTraceLimit = 100; installCommonGlobals(global as any, projectConfig.globals); - // TODO: remove this ASAP, but it currently causes tests to run really slow - global.Buffer = Buffer; - // Report uncaught errors. this.errorEventListener = event => { if (userErrorListenerCount === 0 && event.error) { diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index f6e0d40848cc..a07d7e5a0e75 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -232,12 +232,24 @@ async function runTestInternal( }, }; + const isBrowserEnv = typeof environment.global?.document !== 'undefined'; + // For tests - runtime - .requireInternalModule( - require.resolve('source-map-support'), - ) - .install(sourcemapOptions); + if (isBrowserEnv) { + runtime.requireInternalModule( + require.resolve('source-map-support/browser-source-map-support'), + ); + const sourceMapSupport = environment.global + .sourceMapSupport as typeof sourcemapSupport; + + sourceMapSupport.install({...sourcemapOptions, environment: 'browser'}); + } else { + runtime + .requireInternalModule( + require.resolve('source-map-support'), + ) + .install(sourcemapOptions); + } // For runtime errors sourcemapSupport.install(sourcemapOptions);