diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 33df2ba5dbe6..8df6447e8b00 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -155,6 +155,7 @@ class Runtime { private _virtualMocks: BooleanObject; private _moduleImplementation?: typeof nativeModule.Module; private jestObjectCaches: Map; + private _hasWarnedAboutRequireCacheModification = false; constructor( config: Config.ProjectConfig, @@ -1302,7 +1303,13 @@ class Runtime { moduleRequire.resolve = resolve; moduleRequire.cache = (() => { const notPermittedMethod = () => { - console.warn('`require.cache` modification is not permitted'); + if (!this._hasWarnedAboutRequireCacheModification) { + this._environment.global.console.warn( + '`require.cache` modification is not permitted', + ); + + this._hasWarnedAboutRequireCacheModification = true; + } return true; }; return new Proxy(Object.create(null), { diff --git a/testSetupFile.js b/testSetupFile.js index ef9ed18680f6..7f73aec1ef96 100644 --- a/testSetupFile.js +++ b/testSetupFile.js @@ -8,3 +8,6 @@ // Some of the `jest-runtime` tests are very slow and cause // timeouts on travis jest.setTimeout(70000); + +// this module does some funky stuff with `require.cache`, flooding the terminal with output +jest.mock('stealthy-require', () => (_, m) => m());