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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom cleanup functions in TestScheduler #7093

Closed
piratefsh opened this issue Oct 2, 2018 · 10 comments
Closed

Allow custom cleanup functions in TestScheduler #7093

piratefsh opened this issue Oct 2, 2018 · 10 comments

Comments

@piratefsh
Copy link

馃殌 Feature Proposal

Allow custom cleanup functions to be run by TestScheduler. Currently, TestScheduler only runs cleanup for jest snapshots (code here).

I would like a way to specify a custom cleanup function, or to have an expectation that a custom matcher can export it's own cleanup function.

Motivation

Custom matchers generate snapshots that can be obsolete once the corresponding test files have been removed. See related jest-image-snapshot issue here: americanexpress/jest-image-snapshot#59 (comment)

When working with a custom matcher e.g. jest-image-snapshot, there doesn't seem to be a way to run a cleanup function after all tests have finished running. Custom matchers may also save snapshot files with their own naming format, which may not correspond to jest-snapshot naming conventions,

Example

See motivation above ^

Pitch

A cleanup should run after all tests have been completed, which is known to TestScheduler. As far as I can see, that is the best place that this can happen -- happy to hear out and discuss alternative implementations!

@piratefsh
Copy link
Author

Hey, bumping this -- any thoughts?

@rickhanlonii
Copy link
Member

Hey @piratefsh, it makes sense to me on the surface - how do you recommend we expose hooking into it?

@piratefsh
Copy link
Author

piratefsh commented Oct 19, 2018

Hey @rickhanlonii, my initial thought is that custom matchers can export a cleanup function that can be called by TestScheduler after all tests are done running. This is what jest-snapshot currently does.

For the cleanup to work for snapshot-style matchers, cleanup is passed in as arguments the following:

  • all known test files and snapshot files (via something called HasteFS it seems)
  • a way to resolve test -> snapshot file (this can be implemented by the matcher since it is the one that generates the snaps)

If it cannot find a corresponding test for a snapshot file, it assumes that the snapshot file is no longer valid. This assumes that it's a one-to-one mapping between test and snapshot file though, so there is that limitation.

Also, when running a subset of tests, the cleanup function only affect the related files. I can imagine it to get confusing if I ran a single test suite and it ends up cleaning up old snapshot from unrelated tests.

What do you think? Happy to think this through further and to hear your thoughts.

@SimenB
Copy link
Member

SimenB commented Oct 20, 2018

a way to resolve test -> snapshot file (this can be implemented by the matcher since it is the one that generates the snaps)

How does that play with #6143?

@piratefsh
Copy link
Author

@SimenB Oh cool, didn't know about that PR! It should work with custom resolvers. Since the cleanup function will be implemented by the matcher itself, it should have the access to use its resolver. I don't forsee any conflict there. Did you have any thoughts or concerns?

I am also open to working on this!

@SimenB
Copy link
Member

SimenB commented Oct 20, 2018

A PR with the changes you need would be awesome! No guarantee we'll merge, but often easier to discuss when there's some concrete code to look at 馃檪

@markov00
Copy link

Hey there any news on this?

@github-actions
Copy link

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

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 1, 2022

This issue 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 May 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants