Jest: Spurious `'require.cache' modification is not permitted` warnings since 25.5.0

Created on 29 Apr 2020  路  7Comments  路  Source: facebook/jest

馃挜 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

Regression

Most helpful comment

Released in 25.5.4

All 7 comments

Yeah I've seen those as well in Jest's own tests. https://github.com/facebook/jest/pull/9841 mentions this problem after merge, but apparently forgotten about for the release :grimacing: @SimenB

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 馃檪

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.

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)

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.

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

Released in 25.5.4

Was this page helpful?
0 / 5 - 0 ratings