Skip to content

Commit

Permalink
use browser-version of source-map-support
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 20, 2021
1 parent 3754dc0 commit 1e15a27
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
7 changes: 5 additions & 2 deletions packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts
Expand Up @@ -7,9 +7,8 @@

import {plugins} from 'pretty-format';

const builtInObject = [
const builtInObject: Array<unknown> = [
Array,
Buffer,
Date,
Float32Array,
Float64Array,
Expand All @@ -25,6 +24,10 @@ const builtInObject = [
Uint8ClampedArray,
];

if (typeof Buffer !== 'undefined') {
builtInObject.push(Buffer);
}

const isBuiltInObject = (object: any) =>
builtInObject.includes(object.constructor);

Expand Down
23 changes: 17 additions & 6 deletions packages/jest-runner/src/runTest.ts
Expand Up @@ -206,13 +206,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'),
'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
13 changes: 8 additions & 5 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 1e15a27

Please sign in to comment.