Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e15a27

Browse files
committed
use browser-version of source-map-support
1 parent 3754dc0 commit 1e15a27

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
import {plugins} from 'pretty-format';
99

10-
const builtInObject = [
10+
const builtInObject: Array<unknown> = [
1111
Array,
12-
Buffer,
1312
Date,
1413
Float32Array,
1514
Float64Array,
@@ -25,6 +24,10 @@ const builtInObject = [
2524
Uint8ClampedArray,
2625
];
2726

27+
if (typeof Buffer !== 'undefined') {
28+
builtInObject.push(Buffer);
29+
}
30+
2831
const isBuiltInObject = (object: any) =>
2932
builtInObject.includes(object.constructor);
3033

packages/jest-runner/src/runTest.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,24 @@ async function runTestInternal(
206206
},
207207
};
208208

209+
const isBrowserEnv = typeof environment.global?.document !== 'undefined';
210+
209211
// For tests
210-
runtime
211-
.requireInternalModule<typeof import('source-map-support')>(
212-
require.resolve('source-map-support'),
213-
'source-map-support',
214-
)
215-
.install(sourcemapOptions);
212+
if (isBrowserEnv) {
213+
runtime.requireInternalModule(
214+
require.resolve('source-map-support/browser-source-map-support'),
215+
);
216+
const sourceMapSupport = environment.global
217+
.sourceMapSupport as typeof sourcemapSupport;
218+
219+
sourceMapSupport.install({...sourcemapOptions, environment: 'browser'});
220+
} else {
221+
runtime
222+
.requireInternalModule<typeof sourcemapSupport>(
223+
require.resolve('source-map-support'),
224+
)
225+
.install(sourcemapOptions);
226+
}
216227

217228
// For runtime errors
218229
sourcemapSupport.install(sourcemapOptions);

packages/jest-runtime/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,10 @@ export default class Runtime {
652652

653653
if (options?.isInternalModule) {
654654
moduleRegistry = this._internalModuleRegistry;
655+
} else if (this._isolatedModuleRegistry) {
656+
moduleRegistry = this._isolatedModuleRegistry;
655657
} else {
656-
if (this._isolatedModuleRegistry) {
657-
moduleRegistry = this._isolatedModuleRegistry;
658-
} else {
659-
moduleRegistry = this._moduleRegistry;
660-
}
658+
moduleRegistry = this._moduleRegistry;
661659
}
662660

663661
const module = moduleRegistry.get(modulePath);
@@ -1823,6 +1821,11 @@ export default class Runtime {
18231821
throw moduleNotFoundError;
18241822
}
18251823

1824+
e.message = `Jest: Got error evaluating ${path.relative(
1825+
this._config.rootDir,
1826+
module.filename,
1827+
)}.\n${e.message}`;
1828+
18261829
throw e;
18271830
}
18281831

0 commit comments

Comments
 (0)