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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

--watch mode re-runs all tests on file change, docs are not clear. #10651

Closed
wclr opened this issue Oct 19, 2020 · 11 comments
Closed

--watch mode re-runs all tests on file change, docs are not clear. #10651

wclr opened this issue Oct 19, 2020 · 11 comments

Comments

@wclr
Copy link
Contributor

wclr commented Oct 19, 2020

馃悰 Bug Report

Docs state:

Watch files for changes and rerun tests related to changed files. If you want to re-run all tests when a file has changed, use the --watchAll option instead.

I have two files:
a.test.js with A test suite.
b.test.js with B test suite.

To me, this sounds like if I change file a.test.js then jest only runs test from changed file a.test.js. But Jest reruns all the tests from all two files.

To Reproduce

This is easy to reproduce. I will make a repo if needed. I just want confirmation. That it is not expected behavior. And if it is expected then docs should be updated. And I wonder what is the advice on this issue.

Expected behavior

Run only tests from the changed file.

Link to repl or repo (highly encouraged)

envinfo


  System:
    OS: Windows 10 10.0.19042
    CPU: (6) x64 Intel(R) Core(TM) i5-9600 CPU @ 3.10GHz   
  Binaries:
    Node: 14.4.0 - C:\Program Files\nodejs\node.EXE        
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^26.6.0 => 26.6.0 
@jeysal
Copy link
Contributor

jeysal commented Oct 19, 2020

Yes, it should work as you stated (although 'related to changed files' also means changes to a file that the test imports). Please make a repro.

@wclr
Copy link
Contributor Author

wclr commented Oct 19, 2020

@jeysal this is really strange

So this is what I see in th console after I change a.test.js:

image

I expect to see only PASS info related to test-a, but there is b-test info also. So it is not expected jest's behavior, right?

@jeysal
Copy link
Contributor

jeysal commented Oct 19, 2020

To be clear, changed refers to the current commit as a base. So if you change a and then b, they will now always run until you commit the changes.

@wclr
Copy link
Contributor Author

wclr commented Oct 19, 2020

@jeysal
So changes relate to GIT. not changed files while development watch mode. Ok, this is actually not clear from docs, I think it should be stated more explicitly. What about executing only for just changed file, is it possible to achieve somehow?

@jeysal
Copy link
Contributor

jeysal commented Oct 19, 2020

No, that is not possible (at least with Jest alone).
We would appreciate a PR making the docs clearer!

@jeysal jeysal closed this as completed Oct 19, 2020
@wclr
Copy link
Contributor Author

wclr commented Oct 19, 2020

@jeysal couple related questions on the issue:

  1. https://jestjs.io/docs/en/watch-plugins wonder why in onFileChange is not possible to see the filePath that has been changed, isn't it possible?

  2. Isn't it possible from plugin somehow to get access to findRelatedTestsFromPattern?

@jeysal
Copy link
Contributor

jeysal commented Oct 19, 2020

  1. Jest itself doesn't need to know what caused the file change event, I assume that's why we don't have that information there and don't give it to plugins.
  2. Plugins probably are/should be able to set --findRelatedTests, which would then cause Jest to use findRelatedTestsFromPattern to determine tests to run.

@wclr
Copy link
Contributor Author

wclr commented Oct 19, 2020

@jeysal

Plugins probably are/should be able to set --findRelatedTests, which would then cause Jest to use findRelatedTestsFromPattern to determine tests to run.

Any ideas how? At least in onFileChange hook in projects[0].config there is no prop findRelatedTests.

@jeysal
Copy link
Contributor

jeysal commented Oct 19, 2020

Watch plugins use updateConfigAndRun to trigger a re-run with changed config.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or Reactiflux for questions.
Not sure if findRelatedTests is already an allowed property for watch plugins to update, but if not we'd accept a PR to make it.

@wclr
Copy link
Contributor Author

wclr commented Oct 20, 2020

@jeysal on SO usually difficult to get this level of expertise and people who have it.

updateConfigAndRun is used in run which is on keypress in the menu, I want:

  1. whether to update config (findRelatedTests ) in onFileChange hook, so jest itself would care about the rest process of running only filtered tests considering new setting

  2. or another approach could be to get related test suites list (if something like findRelatedTests method is available) in onFileChange hook and then to filter suites in shouldRunTestSuite hook.

But I believe neither options are available now. Should I create an issue on this?

UPD:

So there is a way to run updateConfigAndRun in onFileChange hook (though only after you presskey in menu).

I've made a PR for passing need options #10659.

@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

No branches or pull requests

2 participants