vitest icon indicating copy to clipboard operation
vitest copied to clipboard

when using `debug` to print to console, output is missing on reruns

Open panick-carousel opened this issue 2 years ago • 1 comments

Describe the bug

I am using the debug tool with vitest and cannot reliably get output from this tool. It appears as tho when in watch mode, vitest clears the console and wipes any debug output under some circumstances.

the debug library writes to stderr rather than stdout, so perhaps the clearing code in vite should account for lines due to stderr somehow ?

Thank you kindly for vitest - it makes life so much better.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-qiyvqq?file=test%2Fsuite.test.ts,package.json&initialPath=vitest

In terminal, press enter to trigger test reruns and observe the output to console from the debug() library.

Then start editing any file to trigger a test rerun, and observe the output to console from debug() is removed.

System Info

System:
    OS: Linux 5.17 Fedora Linux 36 (Server Edition)
    CPU: (16) x64 Intel(R) Xeon(R) E-2286M  CPU @ 2.40GHz
    Memory: 14.55 GB / 19.53 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.6.0 - /run/user/1001/fnm_multishells/788267_1659397396823/bin/node
    Yarn: 1.22.19 - /run/user/1001/fnm_multishells/788267_1659397396823/bin/yarn
    npm: 8.13.2 - /run/user/1001/fnm_multishells/788267_1659397396823/bin/npm

Used Package Manager

yarn

Validations

panick-carousel avatar Aug 02 '22 00:08 panick-carousel

I managed to make the logging from debug be more usable by writing to stdout instead of stderr: debug.log = console.log.bind(console) but even that still fails to display the output roughly 1 in 20 runs.

panick-carousel avatar Aug 02 '22 21:08 panick-carousel

It may be related to length. By trading streams perhaps it is just giving it a little more time before it fills up again. https://github.com/vitest-dev/vitest/issues/2671#issuecomment-1471944292

jcalfee avatar Mar 18 '23 12:03 jcalfee

Turns out, the issue is to do with the spinner used by the default test reporter. If the default test reporter is changed to 'dot' or any other one that doesn't have a spinner in it, the output is preserved with no issue.

https://vitest.dev/config/#reporters

inverted-capital avatar Jan 11 '24 07:01 inverted-capital

actually even 'dot' does some clearing of the terminal, so for #2671 when only a single character is being printed to stderr, it is only visible using a reporter than does not change any existing output on the terminal. Currently the 'tap' reporter is working for even a single character output.

inverted-capital avatar Jan 11 '24 08:01 inverted-capital