Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Add the ability to skip during test execution #2923

Closed
4 tasks done
timbrinded opened this issue Feb 27, 2023 · 7 comments · Fixed by #3966
Closed
4 tasks done

[Request] Add the ability to skip during test execution #2923

timbrinded opened this issue Feb 27, 2023 · 7 comments · Fixed by #3966
Labels
enhancement New feature or request

Comments

@timbrinded
Copy link

timbrinded commented Feb 27, 2023

Clear and concise description of the problem

Currently, describe and tests can be conditionally skipped using skipIf() properties on the top level test functions. However there are many scenarios where it is a lot cleaner, and more logical, to assess whether a test needs to be skipped only during test execution.

Suggested solution

Similar to how Mocha does this, provide test.skip() method on the global runner context which can be used to skip tests as they are being tested.

Make it so that this is callable within any part (beforeEach, beforeAll, describe, test, aftereach, afterall ) of the vitest test runner flow, and will skip that individual test or suite.


example:

describe("Generic Test Suite", function(){

    test("test1", function(){
    // Some state is gathered: const state
    expect(const).to.be.true
    })

    test("test2", async function(){
    // Do some lookup where value not known at initiation time
    const lookupResponse = await fetch(query)

    if (!lookupResponse){
        vi.skip()
    }
    
    expect(lookupResponse.json().field[0]).to.equal(5)

    })

})

Alternative

The skipIf() wrappers are useable but not flexible enough for many async scenarios, as they only affect whether tests get included during the gathering phase. Sometimes you may want tests to be considered skipped, instead of failed, based on responses you get.

Additional context

No response

Validations

@timbrinded timbrinded changed the title Add the ability to skip during test execution [Request]: Add the ability to skip during test execution Mar 2, 2023
@timbrinded timbrinded changed the title [Request]: Add the ability to skip during test execution [Request] Add the ability to skip during test execution Mar 2, 2023
@sheremet-va sheremet-va added the enhancement New feature or request label Mar 18, 2023
@timbrinded
Copy link
Author

Any news or comment about this one?

I've been coming across increasingly more scenarios where you would want to exit a test early and mark it as skipped, during mid execution (e.g. when asserting against prod state with expected but improper values).

@sheremet-va
Copy link
Member

I am not against it, but it should probably be on the context, so:

test('skipped', (t) => {
  t.skip()
})

How should it be implemented - I don't know 🤷🏻 Maybe throw a specific exception that doesn't fail the test, but instead marks it as skipped?

@Aslemammad
Copy link
Member

Aslemammad commented Mar 27, 2023

@sheremet-va We may need to use an abort signal maybe? In that case, each test case should be run in heavy concurrency so we'd be able to skip in any step!
Or even just mark the test as skipped and go to the next test. By throwing a specific "Symbol('skip')"

I'm just throwing ideas!

@johnkingzy
Copy link

For anyone who's looking, this is now supported

describe.skip()
it.skip()

https://vitest.dev/guide/filtering.html#skipping-suites-and-tests

@timbrinded
Copy link
Author

@johnkingzy nope, that is not what this ticket is about. Writing your test with .skip() is not determined at execution but at prepare time.

@johnkingzy
Copy link

@timbrinded thanks for clarifying that; I haven't had to deal with this scenario before so that's good to know.

I'm just curious to know, how is using vi.skip() different from using if/else to skip running subsequent expectations based on a condition.

@timbrinded
Copy link
Author

@johnkingzy skip if only gets checked during prepare, which is useful for disabling tests with environment variables.

It does not offer the flexibility that other test frameworks like mocha have where you can skip during test execution itself.

Any scenario that has non deterministic data in it, such as a fetch call to an API, might want to skip during certain situations. With vitest you simply have to return. Mocha will allow you to this.skip()

@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants