vitest-fail-on-console: Stop Ignoring console.error in Your Tests
The article introduces vitest-fail-on-console, a tool that causes tests to fail when console.error or console.warn messages appear during testing, promoting cleaner and more intentional test output. It highlights how ignored console messages can mask underlying issues even when tests pass. The tool is configurable and integrates easily into existing Vitest setups.
- ▪vitest-fail-on-console makes tests fail when console.error or console.warn is called during test execution.
- ▪The tool helps developers address potential issues instead of ignoring console output that may indicate bugs or misuse.
- ▪Users can configure the tool to allow, silence, or skip specific console messages or test files.
Opening excerpt (first ~120 words) tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 50274) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Recca Tsai Posted on May 2 • Originally published at recca0120.github.io vitest-fail-on-console: Stop Ignoring console.error in Your Tests #testing #vitest #node Originally published at recca0120.github.io All tests pass, but the terminal is full of red console.error output. This is common and easy to ignore — the tests passed, after all. But those errors don't appear out of nowhere. Something went wrong; nobody just noticed.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).