jest icon indicating copy to clipboard operation
jest copied to clipboard

[Feature]: Add a flag to pause at Watch Usage menu

Open ackvf opened this issue 3 years ago • 14 comments

🚀 Feature Proposal

I want a new flag to be able to run jest --watch --xyz in such a way that it doesn't automatically start testing, but lets me decide what set of tests should be executed from the Watch Usage menu.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press o to only run tests related to changed files.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.

Motivation

Whenever I am creating or updating a test suite I use the --watch flag. By default, this command checks which tests are related to files changed since last commit and runs them all. In large projects that can mean executing lots of unnecessary tests. The only way around is wait for the prompt and press a key to interrupt the run, which is uncomfortable and interrupts my work flow.

Determining test suites to run...
 RUNS  src/test/core/dex/uniForks/dmmMaticPair.unit.ts
 RUNS  src/test/core/dex/dodo/dodoMath.unit.ts
 RUNS  src/test/core/dex/balancerV2/balancerV2Pair.unit.ts
 RUNS  src/test/services/token/pricer.unit.ts

Test Suites: 0 of 8 total
Tests:       0 total
Snapshots:   0 total
Time:        52 s

Say I am updating dodoMath.ts and adding new tests to dodoMath.unit.ts. I may change some file that is referenced in other test suites, but I don't really care about their results until I am ready to commit - when I will run the whole lot to see nothing broke.

Example

package.json scripts: "test:watch": "jest --watch --hold"

> yarn test:watch
Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press o to only run tests related to changed files.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.

notice: Determining tests to run is bypassed.

  1. press p
Pattern Mode Usage
 › Press Esc to exit pattern mode.
 › Press Enter to filter by a filenames regex pattern.

 pattern › dodo
 RUNS  src/test/core/dex/dodo/dodoMath.unit.ts

Pitch

Watch is a core Jest functionality, this feature request builds on it.

ackvf avatar Mar 03 '22 23:03 ackvf

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Apr 02 '22 23:04 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar May 02 '22 23:05 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar May 02 '22 23:05 github-actions[bot]

Damn

ackvf avatar May 02 '22 23:05 ackvf

Happy to take a PR here adding --only-watch or something. --watch today implies --only-changed, which is why it starts running tests

SimenB avatar May 03 '22 07:05 SimenB

Does --watch --only-changed false work?

SimenB avatar May 03 '22 07:05 SimenB

@SimenB Running --watch with --only-changed false still runs the same set of tests as without this flag. It seems like the implied -o can't be overriden from cli?

~Anyway I just realised how --watch and --watchAll work so I was thinking that perhaps --watchPick would be even a better choice?~

/edit Jun 1 After all, it seems that --watch and --watchAll both should be combinable with something like --hold, --no-start, --pause or --pause-tests.

--watch --hold
--watchAll --hold

/edit Aug 15 Or better yet --interactive, that can be used on its own, without --watch or --watchAll as the desired action can be chosen from the menu.

--interactive

--interactive, -i

--interactive flag implies --watch. It skips test resolution and goes into Watch Usage menu directly, where the user can choose the next action including watching all tests that is normally triggered by --watchAll.

ackvf avatar May 04 '22 01:05 ackvf

https://user-images.githubusercontent.com/2313018/166613061-cb0b3ddd-7b3a-4702-b243-6efca24023e5.mp4

I am not sure if running jest always took this long as I haven't worked on this repo for over a month, but I am sure it did take long enough to make me think of a way how to bypass it, which resulted in this ticket.

Basically what I am trying to achieve is running the test:watch command and be immediately presented with the "Watch Usage" menu, without having to wait until it finishes, where I could then press "p" and type a pattern for just the files I want.

In the video: 1:31 - Determining test suites to run... 1:52 - testing begins 1:55 - I interrupt the test and "Watch Usage" screen is presented.

ackvf avatar May 04 '22 01:05 ackvf

Hello, do you need any more details? Do you find the video above enough of a motivation to pass this feature request?

PS: I updated my last two comments above.

ackvf avatar May 31 '22 23:05 ackvf

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 01 '22 00:07 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Aug 14 '22 13:08 github-actions[bot]

@SimenB Do you think it would be reasonable to add a bug flag to this ticket too? Given the video above, there is over 1 minute of stale time where jest doesn't seem to do anything. I wonder what is happening.

PS: I edited my post above and added an --interactive flag https://github.com/facebook/jest/issues/12545#issuecomment-1116858021

ackvf avatar Aug 15 '22 11:08 ackvf

I haven't been working on this project for several months now, but I just tried to update the jest ts-jest babel-jest packages to v28 and the long delay seems to be gone, so the "bug" from above seems to be resolved, however, it still tries to run all tests first, before providing me with the menu. It would have been so much easier to skip the test runner and go to the Watch Usage menu directly.

ackvf avatar Aug 15 '22 11:08 ackvf

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Sep 14 '22 11:09 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Oct 14 '22 11:10 github-actions[bot]

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[bot] avatar Nov 14 '22 00:11 github-actions[bot]