vitest icon indicating copy to clipboard operation
vitest copied to clipboard

[Idea] Test Level (Error, Warn, Info)

Open arpowers opened this issue 2 years ago • 1 comments

Clear and concise description of the problem

Hey there,

We are working on CI for a fully featured analytics app and are using Vitest extensively (very happy)..

However, some of the tests we are running are critical path, while others aren't. For example, we are running HTTP checks on services to check health, however, one service is always failing and restarting (due to a Playwright bug)... we'd like to issue a warning here rather than fail the suite.

I suggest a simple option for tests/suites to set a level similar to that in logging (error, warn, info, debug)

Suggested solution

Adding an option for test "level" to describe or test/it..

it(`tests something`, () => {
// test 
}, {
  timeout: 5000, level: 'warn'
})

Alternative

I realize we can name tests to allow them to be run selectively but that couples filename to run context.

Additional context

No response

Validations

arpowers avatar Jul 29 '22 23:07 arpowers

@sheremet-va @antfu this would also solve a separate issue with inline snapshots.

Often we want to use snapshots as a guide for more specific assertions, however, as "assertions" they always fail with timestamps (always different), generated IDs, etc...

Would be nice to print a warning only for failing snapshots instead of hard fail the suite.

arpowers avatar Aug 02 '22 20:08 arpowers

You should probably mock date / id generation to control their outputs rather than "accept" that your test is failing.

https://vitest.dev/guide/mocking.html

If we accept that a test "can" fail, we won't see when we broke the app. If your test is unreliable, either fix it or skip it.

esquevin avatar Oct 25 '22 13:10 esquevin

@esquevin thanks for the response, we mock a lot of stuff actually... the above idea would just help with speed+intent in different testing environments (e.g. CI, dev, vs prod testing)

arpowers avatar Oct 25 '22 14:10 arpowers

I think the idea is interesting. PR welcome!

sheremet-va avatar May 30 '23 18:05 sheremet-va