Skip to content

iTerm2 clear screen does not clear the screen properly #5977

@kxalex

Description

@kxalex

Describe the bug

iTerm2 does not clear the screen properly when vitest is running in watch mode.

Reproduction

Use iTerm2 under Mac.

Run vitest on any project and on re-run not whole screen was cleared, there are some leftovers from previous run.

vitest currently uses to clear the screen and erase scrollback.

this.console.log(`${CLEAR_SCREEN}${ERASE_SCROLLBACK}${message}`)

iTerm2 reacts properly on that sequence, although clear screen sequence leaves 1 page visible and erase scrollback removes the history leaving this not-cleared page.

By flipping the sequence iTerm2 behaves properly.

this.console.log(`${ERASE_SCROLLBACK}${CLEAR_SCREEN}${message}`)

I've added changes in this PR against 1.6.0 version. Although I'm still using 1.5.3 due to cloudflare limitations.

https://github.com/vitest-dev/vitest/pull/5978/files

The erase scrollback and clear screen can be tested in shell using

printf '\e[3J' && printf '\x1Bc' # does not clear all screen
printf '\x1Bc' && printf '\e[3J' # clears everything

This was also tested on default macos terminal and it works fine too.

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M2 Pro
    Memory: 65.22 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.2.0 - /opt/homebrew/bin/node
    npm: 10.7.0 - /opt/homebrew/bin/npm
    pnpm: 9.4.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Brave Browser: 125.1.66.118
    Chrome: 126.0.6478.116
    Safari: 17.5
  npmPackages:
    @vitest/monorepo:  1.5.3

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions