From f830745b0550053eec0690d59967c3f85db65334 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 2 May 2020 09:39:21 +0200 Subject: [PATCH 1/3] fix: remove warning when mutating `require.cache` --- 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..cfbfc6a1b76e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ### Chore & Maintenance +- `[jest-runtime]` Remove warning about `require.cache` modifications + ### 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, From 8a8307378d72f4f35027dc727ce5b15159da6e67 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 2 May 2020 09:40:41 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfbfc6a1b76e..a70684c68d12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ### Chore & Maintenance -- `[jest-runtime]` Remove warning about `require.cache` modifications +- `[jest-runtime]` Remove warning about `require.cache` modifications ([#9946](https://github.com/facebook/jest/pull/9946)) ### Performance From 726bea14ce0ea117dd72f246ebec21cdf1c80324 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 2 May 2020 09:41:12 +0200 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a70684c68d12..c9d72b2c5798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ### Chore & Maintenance -- `[jest-runtime]` Remove warning about `require.cache` modifications ([#9946](https://github.com/facebook/jest/pull/9946)) +- `[jest-runtime]` Do not warn when mutating `require.cache` ([#9946](https://github.com/facebook/jest/pull/9946)) ### Performance