From 78bb25ae050eab7bf2dc1c3b89140957ca2b2537 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 2 May 2020 10:09:48 +0200 Subject: [PATCH] fix: remove warning when mutating `require.cache` (#9946) --- CHANGELOG.md | 2 ++ packages/jest-runtime/src/index.ts | 13 ++----------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b9b4387f3f..c9d72b2c5798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ### Chore & Maintenance +- `[jest-runtime]` Do not warn when mutating `require.cache` ([#9946](https://github.com/facebook/jest/pull/9946)) + ### Performance ## 25.5.3 diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 32c1c751b7f1..7cfcd78bffb0 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -162,7 +162,6 @@ class Runtime { private _virtualMocks: BooleanMap; private _moduleImplementation?: typeof nativeModule.Module; private jestObjectCaches: Map; - private _hasWarnedAboutRequireCacheModification = false; constructor( config: Config.ProjectConfig, @@ -1335,16 +1334,8 @@ class Runtime { moduleRequire.requireMock = this.requireMock.bind(this, from.filename); moduleRequire.resolve = resolve; moduleRequire.cache = (() => { - const notPermittedMethod = () => { - if (!this._hasWarnedAboutRequireCacheModification) { - this._environment.global.console.warn( - '`require.cache` modification is not permitted', - ); - - this._hasWarnedAboutRequireCacheModification = true; - } - return true; - }; + // TODO: consider warning somehow that this does nothing. We should support deletions, anyways + const notPermittedMethod = () => true; return new Proxy(Object.create(null), { defineProperty: notPermittedMethod, deleteProperty: notPermittedMethod,