Skip to content

Commit

Permalink
fix(jsdom-env): remove Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 21, 2022
1 parent 0208815 commit 9a374fd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -76,9 +76,6 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
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) {
Expand Down
22 changes: 17 additions & 5 deletions packages/jest-runner/src/runTest.ts
Expand Up @@ -232,12 +232,24 @@ async function runTestInternal(
},
};

const isBrowserEnv = typeof environment.global?.document !== 'undefined';

// For tests
runtime
.requireInternalModule<typeof import('source-map-support')>(
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<typeof sourcemapSupport>(
require.resolve('source-map-support'),
)
.install(sourcemapOptions);
}

// For runtime errors
sourcemapSupport.install(sourcemapOptions);
Expand Down

0 comments on commit 9a374fd

Please sign in to comment.