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 aea4188
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
7 changes: 5 additions & 2 deletions packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts
Original file line number Diff line number Diff line change
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
25 changes: 19 additions & 6 deletions packages/jest-runner/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type RunTestInternalResult = {
result: TestResult;
};

type SourceMapSupport = typeof import('source-map-support');

function freezeConsole(
testConsole: BufferedConsole | CustomConsole | NullConsole,
config: Config.ProjectConfig,
Expand Down Expand Up @@ -206,13 +208,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 SourceMapSupport;

sourceMapSupport.install({...sourcemapOptions, environment: 'browser'});
} else {
runtime
.requireInternalModule<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
Original file line number Diff line number Diff line change
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 aea4188

Please sign in to comment.