-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
jest --only-changed
ignores changes to module mocks
#8907
Comments
The code for this lives in https://github.com/facebook/jest/blob/c588c18595000d68c98bf8c72d003ff8b3674124/packages/jest-resolve-dependencies/src/index.ts A PR fixing this is very much welcome! 🙂 |
I'm a first time contributer and I'd like to tackle this, but if anyone has the time I'd like some initial feedback on how I should tackle this problem. I've done some digging and I've found this file dependencyExtractor, which has some regex patterns it uses to find dependency declarations, indirectly supplying the resolver in the file linked by @SimenB with dependencies for files. Other patterns matching jest.requireMock are present, but not jest.mock. dependencyExtractor also doesn't include the mocks themselves as dependencies, only the files that are being mocked. I'm guessing that there's a reason it's like this but maybe not. So with all that in mind, would a viable solution be to expand the regexes and add the mock files as dependencies where applicable? If not, some alternatives would be to:
Any feedback is welcome! |
It's hard to tell without trying it out and seeing what else might break, but I believe changing
I think this is tolerable, and will only rarely cause tests being run unnecessarily in practice. I also believe that it's very hard to avoid, because finding out if a mock is used is not easy (it could be declared to be used in lots of places). |
Okay, I'll give that a try then, thanks! |
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. |
🐛 Bug Report
jest --only-changed
does not take mocks into consideration when choosing the tests to run.To Reproduce
Steps to reproduce the behavior (see example repo):
./a
depends on module./b
./b
is mocked in the test of './a`./b
Expected behavior
Test of module
./a
is run when runningjest --only-changed
.The success of the test depends on changes of the mock file - so changing the mock should trigger the test - the same way as changing
./b
directly does.The scenario is not uncommon - could happen when someone is extending the functionality of
./b
, or works on another module that depends on it.Link to repl or repo
https://github.com/tomasz-sodzawiczny/jest-only-changed-vs-mocks
envinfo
Probably not important, but:
The text was updated successfully, but these errors were encountered: