Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: mock stealthy-require in tests #9855

Merged
merged 3 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,9 @@ class Runtime {
moduleRequire.resolve = resolve;
moduleRequire.cache = (() => {
const notPermittedMethod = () => {
console.warn('`require.cache` modification is not permitted');
this._environment.global.console.warn(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related, but noticed this when debugging.

before:
image

after:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB, looks reasonable. We could move up notPermittedMethod helper to the jest-resolve root and wrap it with once, so we get just one warning until jest-resolve reload.

'`require.cache` modification is not permitted',
);
return true;
};
return new Proxy<RequireCache>(Object.create(null), {
Expand Down
3 changes: 3 additions & 0 deletions testSetupFile.js
Original file line number Diff line number Diff line change
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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ yarn why stealthy-require
=> Found "stealthy-require@1.1.1"
info Reasons this module exists
   - "_project_#jest-environment-jsdom#jsdom#request-promise-native" depends on it
   - Hoisted from "_project_#jest-environment-jsdom#jsdom#request-promise-native#stealthy-require"

jsdom/jsdom#2792

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB should it be a best practice recommended for everyone?