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

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Apr 21, 2020

Summary

As mentioned here: #9841 (comment)

This makes me think that we might want to rethink the warning... Is it safe to include this change?

@antongolub @thymikee @jeysal would love your thoughts

EDIT: One thing we can do is only warn once per jest-runtime (meaning per test file). Better than potentially flooding the output at least

Test plan

Green CI without flooded output

@@ -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.

@@ -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?

@SimenB SimenB merged commit 1e2ac30 into jestjs:master Apr 23, 2020
@SimenB SimenB deleted the mock-stealthy-require branch April 23, 2020 09:47
jeysal added a commit to mmkal/jest that referenced this pull request Apr 26, 2020
…pshots

* upstream/master: (39 commits)
  Prints the Symbol name into the error message with a custom asymmetric matcher (jestjs#9888)
  Show coverage of sources related to tests in changed files (jestjs#9769)
  fix: don't /// <reference types="jest" /> (jestjs#9875)
  noCodeFrame respects noStackTrace (jestjs#9866)
  chore: update example to react-native@0.62 (jestjs#9746)
  Improve source map handling when instrumenting transformed code (jestjs#9811)
  Update .vscode/launch.json settings (jestjs#9868)
  chore: verify all packages have the same engine requirement (jestjs#9871)
  fix: pass custom cached realpath function to `resolve` (jestjs#9873)
  chore: mock stealthy-require in tests (jestjs#9855)
  chore: update resolve (jestjs#9872)
  chore: run CircleCI on node 14 (jestjs#9870)
  Add an option to vscode settings to always use workspace TS (jestjs#9869)
  fix(esm): handle parallel imports (jestjs#9858)
  chore: run CI on Node 14 (jestjs#9861)
  feat: add `@jest/globals` package for importing globals explici… (jestjs#9849)
  chore: bump resolve package (jestjs#9859)
  chore(runtime): simplify `createJestObjectFor` (jestjs#9857)
  chore: fix symlink creation failures on windows in tests (jestjs#9852)
  chore: skip mercurial tests when no hg installed (jestjs#9840)
  ...
jeysal added a commit to mmkal/jest that referenced this pull request Apr 26, 2020
…pshots

* upstream/master: (39 commits)
  Prints the Symbol name into the error message with a custom asymmetric matcher (jestjs#9888)
  Show coverage of sources related to tests in changed files (jestjs#9769)
  fix: don't /// <reference types="jest" /> (jestjs#9875)
  noCodeFrame respects noStackTrace (jestjs#9866)
  chore: update example to react-native@0.62 (jestjs#9746)
  Improve source map handling when instrumenting transformed code (jestjs#9811)
  Update .vscode/launch.json settings (jestjs#9868)
  chore: verify all packages have the same engine requirement (jestjs#9871)
  fix: pass custom cached realpath function to `resolve` (jestjs#9873)
  chore: mock stealthy-require in tests (jestjs#9855)
  chore: update resolve (jestjs#9872)
  chore: run CircleCI on node 14 (jestjs#9870)
  Add an option to vscode settings to always use workspace TS (jestjs#9869)
  fix(esm): handle parallel imports (jestjs#9858)
  chore: run CI on Node 14 (jestjs#9861)
  feat: add `@jest/globals` package for importing globals explici… (jestjs#9849)
  chore: bump resolve package (jestjs#9859)
  chore(runtime): simplify `createJestObjectFor` (jestjs#9857)
  chore: fix symlink creation failures on windows in tests (jestjs#9852)
  chore: skip mercurial tests when no hg installed (jestjs#9840)
  ...
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants