vitest icon indicating copy to clipboard operation
vitest copied to clipboard

fix(vitest): ensure restoring terminal cursor on close

Open hi-ogawa opened this issue 1 year ago • 2 comments

Description

  • Closes https://github.com/vitest-dev/vitest/issues/5247

I couldn't identify the actual cause of cursor not getting back only on typecheck run, so I went with using logUpdate.done to explicitly restore the cursor. There could be some deeper bug specific to typecheck run, but I couldn't see anything suspicious.

additional notes

  • log-update is used only for reporters such as dot and default reporters on TTY, so the bug doesn't occur when using --reporter=tap for example.
  • log-update internally uses cli-cursor, which in turn uses restore-cursor. Since we haven't used logUpdate.done, probably we're relying on restore-cursor's automatic restoration, which somehow doesn't work on typecheck mode.

test

  • run pnpm -C examples/typecheck test:run
  • verify cursor is restored

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • [x] It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • [ ] Ideally, include a test that fails without this PR but passes with it.
  • [ ] Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • [ ] Run the tests with pnpm test:ci.

Documentation

  • [ ] If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • [x] Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

hi-ogawa avatar Feb 25 '24 04:02 hi-ogawa

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
Latest commit 366a78b39aeb0173eee47c95187527fa5130b175
Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65dac839d9f47f0008878e9d

netlify[bot] avatar Feb 25 '24 04:02 netlify[bot]

If typecheck run is now interrupted with CTRL+c, does the cursor restore correctly?

I just tested now and surprisingly it restores correctly both before and after this fix.

I'd like to get to the bottom of it. I'm guessing something wrong with restore-cursor or signal-exit, but it would be still bizarre if typecheck + run would affect anything, so I might be looking at the wrong thing.

hi-ogawa avatar Feb 25 '24 08:02 hi-ogawa