vitest: CTRL+C does not immediately stop running tests
Describe the bug
<kbd>CTRL</kbd>+<kbd>C</kbd> does not immediately stop Vitest when tests are slow or stuck.
I’ve seen Vitest being impossible to terminate when tests are stuck because of an issue with fake timers for example, I had to completely close the terminal.
When test are just particularly slow it’s frustrating that Vitest doesn’t immediately stops when pressing <kbd>CTRL</kbd>+<kbd>C</kbd>.
I think this affects bail: 1
too, not 100% sure.
Jest does not have this issue.
Reproduction
- run
npm run test:run slow
- press <kbd>CTRL</kbd>+<kbd>C</kbd> when the test runs
- Vitest hangs and does not immediately terminate
System Info
System:
OS: Windows 10 10.0.22621
CPU: (64) x64 AMD Ryzen Threadripper 3970X 32-Core Processor
Memory: 17.54 GB / 31.86 GB
Binaries:
Node: 20.2.0 - C:\Program Files\nodejs\node.EXE
npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22621.1778.0), Chromium (114.0.1823.43)
Internet Explorer: 11.0.22621.1
npmPackages:
@vitejs/plugin-react: ^4.0.0 => 4.0.0
@vitest/coverage-v8: ^0.32.0 => 0.32.0
vite: ^4.3.5 => 4.3.9
vitest: ^0.32.0 => 0.32.0
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 25 (24 by maintainers)
I’ve been debugging this for a while and I think the root cause is identified now. In #3407 I assumed that
signal-exit
would be the one who handled multipleprocess.on('SIGINT')
handlers, so that on first SIGINT it would call the one defined in Vitest and on second SIGINT it would call its own. But this does not seem to be the case. It looks like this weird SIGINT handling is coming frompnpm
and does not happen on Windows. 😕Testing following script gives different SIGINT handling depending on OS and package manager:
Running the script above and hitting
CTRL
+C
twice, with 1s delay between:Expected: When
CTRL
+C
is pressed, the message should be printed. Process should not terminate as SIGINT is intercepted.MacOS +
pnpm@8.6.2
: Process terminates on secondCTRL
+C
. Handler is called twice on firstCTRL
+C
.MacOS +
npm@9.3.1
: Process does not terminate. Handler is called twice on eachCTRL
+C
.MacOS +
yarn@1.22.19
: On firstCTRL
+C
the script moves to background and cursor is moved to terminal. The logging leaks from background process to terminal. SIGINT handler is called only once.MacOS +
node@18.14.0
, as innode index.mjs
: Handler is called only once. Process does not terminate. This works correctly. ✅Windows 11 +
pnpm@8.6.2
: On firstCTRL
+C
the script moves to background and cursor is moved to terminal. The logging leaks from background process to terminal. SIGINT handler is called only once.Windows 11 +
npm@9.5.1
: Same aspnpm
above.Windows 11 +
node©18.16.0
: Same as on Mac, correct behaviour. ✅So I guess we should not count on catching SIGINT at all. Maybe we should instead capture keys with
process.stdin.on('keypress'
even when in run mode, and simply callprocess.exit
when second key press is caught.I’m now able to reproduce this using the minimal example from above. This is clearly a Windows bug as on macOs the test case exits on second
CTRL
+c
immediately.https://github.com/vitest-dev/vitest/assets/14806298/9dba47fe-b251-444b-be90-08ec9da16e96