Skip to content

vitest should not color output if stdout isn't a tty #9408

@dcaillibaud

Description

@dcaillibaud

Describe the bug

If the environment isn't a tty, vitest doesn't color its output, but if I run vitest in my terminal and pipe its stdout to a file or program, its still color the output (showing ESC[1mESC[44m in the log).

Reproduction

In a project with a configured vitest and a terminal

  • vitest foo => colored output is ok
  • vitest foo > foo.log => ESC[1mESC[44m in the log and shouldn't be there
  • vitest foo |tee -a foo.log => ESC[1mESC[44m in the log and shouldn't be there

Workaround

adding env var NO_COLOR=1 works, NO_COLOR=1 vitest foo > foo.log does not show any color control char in the log, but when stdout isn't a tty it should be useless to add this.

System Info

System:
    OS: Linux 6.12 Debian GNU/Linux 13 (trixie) 13 (trixie)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 18.36 GB / 31.10 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.21.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 11.7.0 - /home/sesamath/usr/bin/npm
    pnpm: 10.26.2 - /home/sesamath/usr/bin/pnpm
  Browsers:
    Chrome: 143.0.7499.192
    Chromium: 143.0.7499.169
    Firefox: 140.6.0esr
    Firefox Developer Edition: 140.6.0esr
  npmPackages:
    playwright: ^1.57.0 => 1.57.0 
    vite: ^7.3.0 => 7.3.0 
    vitest: ^4.0.16 => 4.0.16

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions