vitest icon indicating copy to clipboard operation
vitest copied to clipboard

[Feature] Capture and fail on warnings

Open everett1992 opened this issue 7 months ago • 0 comments

Clear and concise description of the problem

I found pytest's warning capture really useful, it captures warnings during tests and you can configure them to fail the tests.

https://docs.pytest.org/en/stable/how-to/capture-warnings.html

Combined with some NODE_OPTIONS like --pending-deprecation this could be a good way to prepare for node upgrades.

Suggested solution

Add a vitest option to capture warnings (process.on('warning')) and print them after a test run. Add options to fail tests on warnings.

Vitest could try to associate warnings with specific tests (which tests were running when the event was triggered, or which is in the stack trace)

Alternative

I think users could implement this themselves in a global setup file, but it would be easier to configure and recommend as a vitest feature.

Users could also use options like --throw-deprecation but we'd want to separate deprecation's thrown by vitest code from the application (i.e test workers). And seeing a completed test run with all deprecations at the end would be better than failing the test after the first deprecation.

Additional context

No response

Validations

everett1992 avatar May 26 '25 20:05 everett1992