Skip to content

feat: not update snapshots that were not run on test failure#910

Merged
9aoy merged 2 commits intomainfrom
snapshot
Jan 27, 2026
Merged

feat: not update snapshots that were not run on test failure#910
9aoy merged 2 commits intomainfrom
snapshot

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Jan 27, 2026

Summary

should not be updated for snapshots that have not been run when test temporarily fails.

  it('should test snapshot', () => {
    expect({ a: 1, b: 2, c: 4 }).toMatchSnapshot();

    throw new Error('test');

    // should not update snapshot when test temporarily fails
    expect({ a: 1, b: 2, c: 5 }).toMatchSnapshot();
  });

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @9aoy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the reliability of snapshot testing by implementing a crucial safeguard: snapshots will no longer be updated for tests that fail during their execution, even when an update command is issued. This prevents the accidental saving of incorrect or incomplete snapshots, ensuring that only valid test outcomes influence the snapshot baseline. The change includes a core logic modification within the test runner and is thoroughly validated with a new end-to-end test.

Highlights

  • Snapshot Update Logic: Modified the test runner to prevent snapshot updates for tests that fail during execution, even when the update flag (-u) is used. This ensures that only successful tests contribute to snapshot changes.
  • New End-to-End Test: Introduced a new end-to-end test case (e2e/snapshot/file.test.ts) to specifically verify that snapshots associated with failed tests are not updated when the update flag is active.
  • Snapshot Test Fixtures: Added several new snapshot files and a corresponding test file (e2e/snapshot/fixtures/error.test.ts) that intentionally throws an error, serving as a fixture for the new e2e test and demonstrating browser snapshot capabilities.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@9aoy 9aoy changed the title feat: should not be updated for snapshots that have not been run feat: not update snapshots that were not run on test failure Jan 27, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a feature to prevent snapshot updates for tests that fail, which is particularly useful when running with the update flag (-u). The implementation correctly marks snapshots of failed tests as 'skipped' within the test runner, preventing them from being pruned as obsolete. This change is well-supported by a new end-to-end test that validates the new behavior. Additionally, an existing test was improved to correctly await the completion of a command-line process, enhancing test stability. The changes are logical, well-tested, and improve the snapshot testing experience.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5ccbb42
Status:⚡️  Build in progress...

View logs

@9aoy 9aoy merged commit 5605482 into main Jan 27, 2026
11 of 12 checks passed
@9aoy 9aoy deleted the snapshot branch January 27, 2026 09:17
@fi3ework fi3ework mentioned this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant