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

when renaming an "it" block or "describe" block, remove obsolete snapshots in watch mode #10699

Closed
capaj opened this issue Oct 25, 2020 · 3 comments

Comments

@capaj
Copy link
Contributor

capaj commented Oct 25, 2020

馃殌 Feature Proposal

when a change in the name of "it" block or "describe" block occurs currently there is a new snapshot written in the watch mode. Old ones remain there.
I would like it if they were automatically removed at the end of the run. Jest prints out a warning anyway like this:
image
I would like it if jest removed the snapshots automatically when the number of newly created snapshots matches the number of created ones.
Yes this can potentially be dangerous, but in 99% of cases it is just a rename of a block. Also we can probably do additional check to see if this indeed was just a snapshot rename or not by inspecting the name of obsolete snapshots.
If a describe block changed, the ending of the name of the snapshot will match to the one removed.
If a it block changed name, the beginning of the name of the snapshot will match to the one removed.
This logic should also work for nested describes-basically when a new snapshot export name still partially matches the old one.
If a user renames both blocks at once we can keep the old behavior as we wouldn't be able to match any parts.

Motivation

some test runs might take a while and it is tedious to keep rerunning them twice every time I want to change a name of a single block.

Example

I have a file like this:

describe('A', () => {
  it('B', async () => {
    expect(1).toMatchSnapshot()
  })
})

and a snapshot:

exports[`A B 1`] = `1`;

When I change the "B" to "C" in watch mode, I get this in my snapshot file:

exports[`A B 1`] = `1`;

exports[`A C 1`] = `1`;

This proposal is about changing this output to be just:

exports[`A C 1`] = `1`;

Pitch

@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 5, 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 5, 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

1 participant