vitest
vitest copied to clipboard
when using `debug` to print to console, output is missing on reruns
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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
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.
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
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
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.