How to disable terminal colors in the vitest snashots? #6587
Replies: 3 comments 3 replies
-
ahh wait this seems to work by using "scripts": {
"test": "cross-env-shell NO_COLOR=true vitest --watch --config ./vitest/vitest.config.ts",
} is that the best way to do it on a Windows and to make it cross-compatible? and this seems to work for the VSCode debugger {
"name": "Vitest - Debug Current Test File",
"type": "node",
"env": {
"NO_COLOR": "true"
},
"request": "launch",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}", "--pool", "forks", "--no-watch", "--config", "./vitest/vitest.config.ts"],
"smartStep": true,
"console": "integratedTerminal"
}, |
Beta Was this translation helpful? Give feedback.
-
The Something like this should work nicely: import { expect } from 'vitest';
import stripAnsi from 'strip-ansi'
expect.addSnapshotSerializer({
serialize: (val) => stripAnsi(val),
test: () => true,
}); |
Beta Was this translation helpful? Give feedback.
-
Since Node.js v16.11 the built in |
Beta Was this translation helpful? Give feedback.
-
I'm having unit tests issues with my snapshots after switching from
chalk
topicocolors
in Lerna-Lite via this PR. I saw this Vitest issue #841 which says to useNO_COLOR
which seems to help in the CI and makes my Lerna-Lite PR pass but I can't figure how to disable it on my local Windows computer.I tried setting this in my
.env
file but that doesn't workI also tried the Vitest
--no-color
CLI option but that doesn't work either. I also have the problem while running VSCode debugger as well. It's great that it now works in the CI but I really I could get my tests to pass locally as well.The code below works in the CI, but how can I do the same locally?
- name: Run Vitest unit tests env: NO_COLOR: true run: pnpm test:coverage
Beta Was this translation helpful? Give feedback.
All reactions