Skip to content

Commit 1e2ac30

Browse files
authored
chore: mock stealthy-require in tests (#9855)
1 parent 9443889 commit 1e2ac30

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/jest-runtime/src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class Runtime {
155155
private _virtualMocks: BooleanObject;
156156
private _moduleImplementation?: typeof nativeModule.Module;
157157
private jestObjectCaches: Map<string, Jest>;
158+
private _hasWarnedAboutRequireCacheModification = false;
158159

159160
constructor(
160161
config: Config.ProjectConfig,
@@ -1302,7 +1303,13 @@ class Runtime {
13021303
moduleRequire.resolve = resolve;
13031304
moduleRequire.cache = (() => {
13041305
const notPermittedMethod = () => {
1305-
console.warn('`require.cache` modification is not permitted');
1306+
if (!this._hasWarnedAboutRequireCacheModification) {
1307+
this._environment.global.console.warn(
1308+
'`require.cache` modification is not permitted',
1309+
);
1310+
1311+
this._hasWarnedAboutRequireCacheModification = true;
1312+
}
13061313
return true;
13071314
};
13081315
return new Proxy<RequireCache>(Object.create(null), {

testSetupFile.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
// Some of the `jest-runtime` tests are very slow and cause
99
// timeouts on travis
1010
jest.setTimeout(70000);
11+
12+
// this module does some funky stuff with `require.cache`, flooding the terminal with output
13+
jest.mock('stealthy-require', () => (_, m) => m());

0 commit comments

Comments
 (0)