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

Spurious 'require.cache' modification is not permitted warnings since 25.5.0 #9916

Closed
BBosman opened this issue Apr 29, 2020 · 8 comments · Fixed by #9946
Closed

Spurious 'require.cache' modification is not permitted warnings since 25.5.0 #9916

BBosman opened this issue Apr 29, 2020 · 8 comments · Fixed by #9946

Comments

@BBosman
Copy link

BBosman commented Apr 29, 2020

💥 Regression Report

Since upgrading to version 25.5.0 I keep getting this warning logged for each test: 'require.cache' modification is not permitted.

I assume this is due to #9841, but as this is a change in existing behaviour (and thus a breaking change) I would have not expected this in a minor release, but in a major release.

Last working version

Worked up to version: 25.4.0

Stopped working in version: 25.5.0

Expected behavior

I would have expected this to work as before, without logging warnings.

Run npx envinfo --preset jest

System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Binaries:
Node: 12.14.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
npmPackages:
jest: ^25.5.0 => 25.5.0

@jeysal
Copy link
Contributor

jeysal commented Apr 29, 2020

Yeah I've seen those as well in Jest's own tests. #9841 mentions this problem after merge, but apparently forgotten about for the release 😬 @SimenB

@SimenB
Copy link
Member

SimenB commented Apr 29, 2020

There's zero change in behavior - messing with require.cache never did anything. However, it does warn since people normally expect it to have an effect (which I personally wouldn't consider a breaking change, but I can understand that some folk do).

However, I can understand it's annoying (I had to mock out stealthy-require in jest's own tests: #9855), so I'm down with not warning and keep pretending it does something if people prefer an "out of sight out of mind" approach 🙂

@BBosman
Copy link
Author

BBosman commented Apr 29, 2020

I'm all for warning as it does serve a purpose, but would postpone that to a (future) major release and "silence" them for now.

@SimenB
Copy link
Member

SimenB commented Apr 30, 2020

As mentioned in #9841, I'm currently leaning towards removing the warning for Jest 25. Then in Jest 26 I'd like to introduce an API for clearing a single module from the cache (rather than all modules). We could then make deletions in require.cache call that under the hood so it'd actually work. Not sure about what e.g. stealthy-require does though, which is replace the whole cache, do some stuff, then put the old cache back. What import-fresh should be possible to support, though.

Thoughts?

(FWIW, what stealthy-require does is supported by jest.isolateModules(), but I don't think we're able to seamlessly map the operations. That should be trivial with deletions)

mohanraj-r pushed a commit to salesforce/sa11y that referenced this issue Apr 30, 2020
@ghiscoding
Copy link
Contributor

ghiscoding commented May 1, 2020

So how do we get rid of this warning and/or how to fix it? I can't figure out a way to bypass the warning and I have over 2000 tests and I see this warning 2000 times (with 3-4 lines for the stack trace), my tests become unreadable. I also tried to revert to the previous version but somehow that doesn't seem to work.

My project is Aurelia-Slickgrid if that helps.

@dpkshrma
Copy link

dpkshrma commented May 2, 2020

It gives these warnings in "jest": "25.3.0", as well :(

@SimenB
Copy link
Member

SimenB commented May 2, 2020

Released in 25.5.4

@github-actions
Copy link

This issue 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 a pull request may close this issue.

5 participants