Skip to content

Commit

Permalink
chore: mock stealthy-require in tests (#9855)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 23, 2020
1 parent 9443889 commit 1e2ac30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -155,6 +155,7 @@ class Runtime {
private _virtualMocks: BooleanObject;
private _moduleImplementation?: typeof nativeModule.Module;
private jestObjectCaches: Map<string, Jest>;
private _hasWarnedAboutRequireCacheModification = false;

constructor(
config: Config.ProjectConfig,
Expand Down Expand Up @@ -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<RequireCache>(Object.create(null), {
Expand Down
3 changes: 3 additions & 0 deletions testSetupFile.js
Expand Up @@ -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());

0 comments on commit 1e2ac30

Please sign in to comment.