Skip to content

Commit

Permalink
fix: remove warning when mutating require.cache (#9946)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored May 2, 2020
1 parent 649796d commit 78bb25a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class Runtime {
private _virtualMocks: BooleanMap;
private _moduleImplementation?: typeof nativeModule.Module;
private jestObjectCaches: Map<string, Jest>;
private _hasWarnedAboutRequireCacheModification = false;

constructor(
config: Config.ProjectConfig,
Expand Down Expand Up @@ -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<NodeJS.NodeRequireCache>(Object.create(null), {
defineProperty: notPermittedMethod,
deleteProperty: notPermittedMethod,
Expand Down

0 comments on commit 78bb25a

Please sign in to comment.