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

Add onCleanup hook #7258

Open
4 tasks done
sheremet-va opened this issue Jan 15, 2025 · 0 comments
Open
4 tasks done

Add onCleanup hook #7258

sheremet-va opened this issue Jan 15, 2025 · 0 comments
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@sheremet-va
Copy link
Member

Clear and concise description of the problem

There are times when the test runners needs to run a cleanup callback manually and not tied it to the test runner lifecycle (avoid beforeEach/afterEach). A good example of this is calling the cleanup when switching tests in the Browser Mode UI.

Suggested solution

@vitest/runner can expose an onCleanup hook. Consumers of the runner can decide when to run passed down callbacks. By default, Vitest will run those callbacks after each test (when running tests in the Node.js environment). Vitest Browser Mode will also run those hooks after each test, except for the last one, so the UI is still available.

Alternative

No response

Additional context

See #7141 for more details

Validations

@sheremet-va sheremet-va added the p2-nice-to-have Not breaking anything but nice to have (priority) label Jan 15, 2025
@sheremet-va sheremet-va moved this to P2 - 3 in Team Board Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Status: P2 - 3
Development

No branches or pull requests

1 participant