-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Vitest should not eat stdin
while running non-interactively
#3928
Comments
I assume the fix for this is diff --git a/packages/vitest/src/node/stdin.ts b/packages/vitest/src/node/stdin.ts
index f4b3b82d..69c734f1 100644
--- a/packages/vitest/src/node/stdin.ts
+++ b/packages/vitest/src/node/stdin.ts
@@ -125,18 +125,18 @@ export function registerConsoleShortcuts(ctx: Vitest) {
function on() {
off()
rl = readline.createInterface({ input: process.stdin, escapeCodeTimeout: 50 })
readline.emitKeypressEvents(process.stdin, rl)
- if (process.stdin.isTTY)
+ if (process.stdin.isTTY && ctx.config.watch)
process.stdin.setRawMode(true)
process.stdin.on('keypress', keypressHandler)
}
function off() {
rl?.close()
rl = undefined
process.stdin.removeListener('keypress', keypressHandler)
- if (process.stdin.isTTY)
+ if (process.stdin.isTTY && ctx.config.watch)
process.stdin.setRawMode(false)
}
on() Unfortunately, I can not get vitest to build correctly on my machine. After |
This is done for test interruption via
It used to be done by relying on
|
I see, so as per this, raw mode is used to get node to emit What I don't quite get is why SIGINT is not working universally, I thought it did and that's what I was using in many applications so far. Never once had I resort to keypress events. |
Another problem introduced by not using SIGINT is that I'm pretty sure other things than CTRL-C can invoke SIGINT, for example when the OS is shutting down, the process manager will sind SIGINT to all processes followed by SIGTERM. By not catching SIGINT any more, you force the OS to SIGTERM the process eventually, which is not really the fine way to gracefully shut down a process. So I think what should be done is:
Interesting tidbit about
|
When SIGINT is not caught, the default Nodejs behaviour will kick in. It will forcefully stop everything. So the current feature is that you can use
I have no idea how to fix this. Any help is appreciated. Here is the minimal reproduction case for studying this. It requires no dependencies: #3569 (comment). |
What's worse, Imho |
Sounds like we should revert it then. Any ideas how to support #3373 when not listening for |
Not directly revert, but find a cleaner solution to SIGINT handling that does not involve setting terminal to raw mode would be all I'm asking for. I think some of the code may assume that SIGINT only comes via |
Vitest is not listening for |
Interesting, does node install a default SIGINT handler in case the app does not register one? The docs do not mention it, they only say:
I think vitest should always install this handler. Only after switching into raw mode for |
Vitest used to do that but it did not work on all platforms and package managers: #3569 (comment). |
It does sound like bugs in those package managers, but maybe I'll set up a test repo for this which could then run in GH Actions on the various package managers/os combos to really narrow it down. |
vitejs/vite#14342 is related for vite. It outlines a few more caveats that raw mode brings. Likely vitest could use a similar implementation. |
That would not work for Vitest as that completely removes reacting to I think the only way to fix this is to revert changes of https://github.com/vitest-dev/vitest/pull/3642/files#diff-9c6031e2e4327db659ca4d448e18039217e6bf3dadfd843e1a5c0cb06297edcaL90-L93. To fulfil #3373 we would need #3549 and it's successor #3732. |
Enabling raw mode in non-interactive run-mode seems to also cause issues when running multiple Vitest commands in parallel using vitest run --shard=1/4 & \
vitest run --shard=2/4 & \
vitest run --shard=3/4 & \
vitest run --shard=4/4 & \
wait # https://man7.org/linux/man-pages/man2/waitpid.2.html It doesn't run the commands before Time to revert this change and keep raw mode disabled in run-mode. |
Describe the bug
While vitest is running non-interactively, e.g. with
watch: false
, anything typed into the terminal is needlessly consumed by the process but not actually used. I find this disturbing as I often like to type the next command while the current one is still running.I assume the reason for this is because vitest sets the
stdin
stream into raw mode despite having no reason to do so whenwatch
is not enabled. The only thing is effectively does is prevent echo and this is only useful on a interactive prompt.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: