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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI doesn't currently allow choosing filename test pattern until all tests are completed #3128

Closed
6 tasks done
ghiscoding opened this issue Apr 3, 2023 · 6 comments · Fixed by #3163
Closed
6 tasks done
Assignees
Labels
enhancement New feature or request

Comments

@ghiscoding
Copy link
Contributor

ghiscoding commented Apr 3, 2023

Describe the bug

I'm migrating Jest unit tests to Vitest in Lerna-Lite (a very light fork of Lerna) and I need to use --no-threads because a few tests requires the use of process.chdir() and because of the no thread, it takes well over a 2min for all tests to complete and during that period the CLI is locked and I cannot use the CLI filename pattern. That's not the case in Jest, I can type in a pattern right after the CLI process starts. I'm on Windows and I know the Lerna/Lerna-Lite tests are running slower on Windows, so the fact that I'm on Windows might be worst for me but still I think the CLI should allow keyboard events even when the unit tests are being performed

Reproduction

Have a long running unit test suite and while it's running (and not completed), try choosing any CLI options while the test runs and you'll see that you can't. That's also true for all CLI commands, for example you can't Quit, by typing "q", until all unit tests are finished.

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 7.50 GB / 31.75 GB
  Binaries:
    Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 111.0.5563.147
    Edge: Spartan (44.19041.1266.0), Chromium (111.0.1661.54)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @vitejs/plugin-vue: ^4.1.0 => 4.1.0
    @vitest/coverage-c8: ^0.29.8 => 0.29.8
    vite: ^4.2.1 => 4.2.1
    vitest: ^0.29.8 => 0.29.8

Used Package Manager

yarn

Validations

@ghiscoding ghiscoding changed the title CLI doesn't currently allow add a filename test pattern until all tests are completed CLI doesn't currently allow choosing filename test pattern until all tests are completed Apr 3, 2023
@AriPerkkio
Copy link
Member

You can pass the filename pattern as CLI argument when starting Vitest.

<root>
├── package.json
├── tests
|  ├── animals.test.ts
|  └── math.test.ts
└── vitest.config.ts
$ pnpm run watch math

> vitest watch "math"

 ✓ tests/math.test.ts (2)
   ✓ sum
   ✓ multiply

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  07:49:57
   Duration  351ms (transform 24ms, setup 0ms, collect 12ms, tests 3ms)

 PASS  Waiting for file changes...
       press h to show help, press q to quit

I need to use --no-threads because a few tests requires the use of process.chdir()

You might want to look into poolMatchGlobs option and keep rest of the tests in threads:

poolMatchGlobs: [
  // These tests depend on APIs unavailable in worker_threads, run them in child_process instead:
  ['**/tests/**/some-name.*', 'child_process'],
]

@ghiscoding
Copy link
Contributor Author

I know we can pass a pattern directly to the CLI but that is not exactly what I'm asking here and I would never start Vitest with a pattern since I always start it in watch mode. What I'm saying is really that Jest allows us to use the keyboard at any point in time to change pattern or even quit the CLI (Jest never blocks keyboard input). This is not the case with Vitest, it blocks keyboard input (or simply doesn't listen) when a test (or all tests) are running and that is a problem.

@AriPerkkio
Copy link
Member

I know we can pass a pattern directly to the CLI but that is not exactly what I'm asking here

The CLI argument does exactly what the issue title asks for but maybe that's just nitpicking about the title. So the request here is to be able to stop test execution in watch mode.

I think this is a bit related to #1459, or at least would enable that feature once implemented.

@ghiscoding
Copy link
Contributor Author

Feel free to change the title with more appropriate description and yes I would like to be able to use any of the CLI options at any point in time and not have to wait for the entire test execution to complete in watch mode (which in my case is 1.5-2min on Windows, so it's painful to wait that long). Jest allows me to do that at any point in time but Vitest doesn't.

It's not exactly like #1459, I would be nice for sure but it's not really the problem that I'm trying to highlight here. We can't seem to be able to use any CLI option (by keyboard event) when the test execution is in progress (for example try typing "q" to quit and Vitest is unresponsive to it until the test execution is completed)

@AriPerkkio
Copy link
Member

The keypress is currently intentionally blocked when tests are running. There is no support for stopping on-going test execution at the moment.

// is running, ignore keypress
if (ctx.runningPromise)
return

@AriPerkkio AriPerkkio added the enhancement New feature or request label Apr 4, 2023
@ghiscoding
Copy link
Contributor Author

Thanks for confirming, that's what I taught. If you guys prefer to have this locked by default, then I wouldn't mind having to unlock via a flag.

AriPerkkio added a commit to AriPerkkio/vitest that referenced this issue Apr 9, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants