question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[jest-snapshot] Custom Snapshot Directories confuse the Obsolete Snapshot Logger

See original GitHub issue

šŸ› Bug Report

When using the new snapshot resolver feature: https://github.com/facebook/jest/pull/6143, the ā€œObsoleteā€ Snapshot checker is deciding that all my snapshots are obsolete after a test run.

To Reproduce

  1. Using a simple project, configure a snapshot resolver to move your snapshot files to a different directory-structure.
  2. Run yarn test notice all your tests pass, and snapshots are in their new location
  3. Notice that it says 45 snapshot files obsolete from 45 test suites.
  4. Run jest -u to remove obsolete snapshots, notice that all your snapshots are gone.

Expected behavior

I would expect that the snapshot files that just got written to wouldn’t be considered instantly obsolete.

Speculation: It looks like the custom snapshotResolver isn’t invoked when analyzing obsolete snapshots, so Jest doesn’t know that these files were actually written to, or something else is weird.

Link to repl or repo (highly encouraged)

I haven’t yet figured out how to do Snapshot Testing in repl.it, will upload a repo shortly if I can’t find an example.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
  Binaries:
    Node: 10.10.0 - /usr/local/bin/node
    Yarn: 1.9.4 - /usr/local/bin/yarn
    npm: 6.0.0 - /usr/local/bin/npm
  npmPackages:
    @types/jest: 23.x => 23.3.7 
    jest: ^24.0.0-alpha.1 => 24.0.0-alpha.1 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vicasascommented, Apr 2, 2021

This error still continues. I’m with the latest version of jest.

This is my configuration:

module.exports = {
  // resolves from test to snapshot path
  resolveSnapshotPath: (testPath, snapshotExtension) =>
    testPath
      .replace('__tests__', '__snapshots__')
      .replace('components', '__snapshots__') + snapshotExtension,

  // resolves from snapshot to test path
  resolveTestPath: (snapshotFilePath, snapshotExtension) =>
    snapshotFilePath
      .replace('__snapshots__', '__tests__')
      .replace('__snapshots__', 'components')
      .slice(0, -snapshotExtension.length),

  // Example test path, used for preflight consistency check of the implementation above
  testPathForConsistencyCheck: 'some/__tests__/example.test.js',
}

image

0reactions
github-actions[bot]commented, May 10, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are obsolete snapshots and snapshot files?
It's been a while I posted this question and by know I can answer it myself: "Obsolete" refers to snapshots or snapshot files,Ā ......
Read more >
Snapshot Testing
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
React Snapshot Testing With Jest: An Introduction With ...
It's a technique for testing React components. Snapshot testing ensures that your UI doesn't change unexpectedly. Further, we'll be using theĀ ...
Read more >
jest-snapshot | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Use Jest's Snapshot Testing Feature
Before Jest snapshotting, when I wrote this kind of test, I would console log the results and then copy/paste it into my assertion...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found