vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.68k stars 1.14k forks source link

cli filtering in watch mode when `p` is pressed early #3889

Open SimonSiefke opened 1 year ago

SimonSiefke commented 1 year ago

Describe the bug

When running vitest in watch mode, filtering is not possible. It first runs all tests (which can take several minutes) before filtering works.

Expected behaviour

When pressing p to filter, test runs stop and it it possible to filter. This is how it works in jest.

Actual behaviour

When pressing p to filter while tests are running, tests do not stop and one needs to wait until all tests finished before it is possible to filter

Reproduction

https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/basic?initialPath=__vitest__/

System Info

System:
    OS: Linux 6.2 Ubuntu 23.04 23.04 (Lunar Lobster)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 2.46 GB / 7.65 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.3.1 - ~/.nvm/versions/node/v20.3.1/bin/node
    Yarn: 3.5.1 - ~/.nvm/versions/node/v20.3.1/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v20.3.1/bin/npm
    pnpm: 8.6.9 - ~/.nvm/versions/node/v20.3.1/bin/pnpm
  Browsers:
    Chrome: 115.0.5790.110

Used Package Manager

npm

Validations

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

AriPerkkio commented 1 year ago

Which version of Vitest are you using? Please include it in the System info section. There were some fixes related to this couple of months ago.

SimonSiefke commented 1 year ago

Thanks for looking into this!

I can reproduce the issue with vitest version: 0.34.1.

Here is a better repo for reproducing the issue: https://github.com/SimonSiefke/vitest-issue

Also I made this screencast of the issue with vitest continuing to run all tests after pressing p:

https://github.com/vitest-dev/vitest/assets/23744935/9d5a940d-2daf-4933-8ce2-93047ea97da3

AriPerkkio commented 1 year ago

I'm unable to reproduce using the repository. In the recording below I let the first 4 tests finish, then click the terminal area and press p. Tests are cancelled.

https://github.com/vitest-dev/vitest/assets/14806298/ff846277-9543-4b9d-84e7-4844fb9c6ebc

In the recording I'm using VS Code's built-in terminal. Could you try other ones and see if the issue still comes up?

SimonSiefke commented 1 year ago

Here is another recording with gnome-terminal. I'm pressing p relatively early: After the blue DEV shows up but before the first test outputs are visible.

https://github.com/vitest-dev/vitest/assets/23744935/eaa9a3bc-008c-4b77-81aa-29b51b672174

When I haven't pressed p early and press p only after 4 tests have finished, it still may wait up to 3 seconds for the next 4 tests to finish but then tests are stopped as expected.

I hope this helps!

AriPerkkio commented 1 year ago

Pressing the key early enough seems to cause some weird edge case. Tests are not cancelled as early as possible. I'm able to reproduce this now.