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

Allow to skip tests asynchronously in jest-circus, closes #8604 #9944

Closed
wants to merge 1 commit into from

Conversation

MrLoh
Copy link

@MrLoh MrLoh commented May 1, 2020

This is a proof of concept for asynchronously skipping tests as discussed in #8604. If this functionality will be considered as an addition, I will write tests and documentation.

TODO:

  • update changelog
  • update docs

Summary

As described in #8604 and #7245 when using jest for e2e tests with e.g. puppeteer or detox, there are many valid use cases for wanting to abort tests programmatically based on previous test results. To enable doing that asynchronously, the API needs to add a skip function that is available during test execution and skips the test when called. Adding this to the API would also allow to easily implement various versions of bailing (see #6527) or stepped tests (see #8387).

This PR adds a skip: () => Promise<void> function to the testContext in jest-circus, so it can be called as return this.skip() in the test fn to skip the currently running test. Alternatively the skip function could be passed to the test fn as a second argument, similar to how done is passed (this might be the more modern approach, as it would support arrow functions).

The main point is to demonstrate that the implementation of this in jest-circus is pretty trivial and adds minimal complexity as all that skip needs to do is to dispatch the test_skip event and prevent the dispatch of test_done.

Alternatively a new canceled state could be added to tests and a test_cancel event could be fired, but I would advise against that, as it will increase the API surface even more.

TODO:

  • write proof of concept
  • agree on API spec
  • refactor and write type definitions

Test plan

TODO:

  • write tests

@Mouvedia
Copy link

#10686 has been merged can we have step now?

@PeterCassell92
Copy link

Would love to see this implemented.

@github-actions
Copy link

github-actions bot commented Feb 2, 2023

This PR is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added Stale and removed Stale labels Feb 2, 2023
@fguitton
Copy link

fguitton commented Feb 3, 2023

Not stale 🎈

@matthew-black
Copy link

This would be rad, but I don't understand why we can just have some kind of additional flag. Maybe --bail-fast or something?

@albertodiazdorado
Copy link

I'd love to have this feature

@MrLoh MrLoh closed this Dec 1, 2023
Copy link

github-actions bot commented Jan 1, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants