From 1e15a27553ad6bc8a039f566ca1e0772cdcf1ce4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 20 Mar 2021 09:59:36 +0100 Subject: [PATCH] use browser-version of source-map-support --- .../src/deepCyclicCopyReplaceable.ts | 7 ++++-- packages/jest-runner/src/runTest.ts | 23 ++++++++++++++----- packages/jest-runtime/src/index.ts | 13 +++++++---- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts b/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts index 8928927b8d2d..9c3dd0ac9d26 100644 --- a/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts +++ b/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts @@ -7,9 +7,8 @@ import {plugins} from 'pretty-format'; -const builtInObject = [ +const builtInObject: Array = [ Array, - Buffer, Date, Float32Array, Float64Array, @@ -25,6 +24,10 @@ const builtInObject = [ Uint8ClampedArray, ]; +if (typeof Buffer !== 'undefined') { + builtInObject.push(Buffer); +} + const isBuiltInObject = (object: any) => builtInObject.includes(object.constructor); diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index 4e8237c283ec..1581461e7894 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -206,13 +206,24 @@ async function runTestInternal( }, }; + const isBrowserEnv = typeof environment.global?.document !== 'undefined'; + // For tests - runtime - .requireInternalModule( - require.resolve('source-map-support'), - '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); diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 04521637efc0..5e2b20cf20cc 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -652,12 +652,10 @@ export default class Runtime { if (options?.isInternalModule) { moduleRegistry = this._internalModuleRegistry; + } else if (this._isolatedModuleRegistry) { + moduleRegistry = this._isolatedModuleRegistry; } else { - if (this._isolatedModuleRegistry) { - moduleRegistry = this._isolatedModuleRegistry; - } else { - moduleRegistry = this._moduleRegistry; - } + moduleRegistry = this._moduleRegistry; } const module = moduleRegistry.get(modulePath); @@ -1823,6 +1821,11 @@ export default class Runtime { throw moduleNotFoundError; } + e.message = `Jest: Got error evaluating ${path.relative( + this._config.rootDir, + module.filename, + )}.\n${e.message}`; + throw e; }