-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[jest-snapshot] Custom Snapshot Directories confuse the Obsolete Snapshot Logger #7257
Comments
My SnapshotResolver: const path = require("path");
const rootDir = path.resolve(__dirname, "..", "..");
const distDir = path.join(rootDir, "dist");
const srcDir = path.join(rootDir, "src");
// const debug = console.debug;
const debug = () => {
return;
};
module.exports = {
/** resolves from test to snapshot path */
resolveSnapshotPath: (testPath, snapshotExtension) => {
const result =
testPath
.replace("__tests__", "__tests__/__snapshots__")
.replace(distDir, rootDir) + snapshotExtension;
debug("testPath", testPath, snapshotExtension, result);
return result;
},
/** resolves from snapshot to test path */
resolveTestPath: (snapshotFilePath, snapshotExtension) => {
const result = snapshotFilePath
.replace("__snapshots__/", "")
.replace(distDir, rootDir)
.slice(0, -snapshotExtension.length);
debug("snapshotFilePath", snapshotFilePath, snapshotExtension, result);
return result;
},
}; |
I wonder if the root cause is related to #6773 ? |
@viddo would you be able to investigate this?
You might be able to use code sandbox, but a repository might be even easier |
@SimenB This Issue suggests that Snapshot testing in CodeSandbox might happen in 3.0, but it's still in progress: codesandbox/codesandbox-client#513 So I guess I'll do a repo at some point, then! |
I have a repro, packaging it up shortly! |
Reproduction provided here! https://github.com/fbartho/jest-snapshot-custom-paths-bug-reproduction @SimenB -- please let me know if there's anything further I can do to help! I've verified it occurs on
|
@facebook-github-bot label 🐛 Bug |
@facebook-github-bot label Has Repro |
First, sorry for late reply, have had some busy weeks. The bug itself is in the custom resolver it turns out, I sent a PR on the reproduce repo (thanks for setting that up BTW), see https://github.com/fbartho/jest-snapshot-custom-paths-bug-reproduction/pull/1/files We did add a "preflight" check with the intention of catching prevent this very scenario from happening, but as can be seen in this reproduce it's quite obvious it's insufficient. 😞 A proper sanity check will need to do know exactly what kind of transformation the customer resolver is doing to validate it (in this particular case remapping src<->dist). The simplest and most straight forward idea I can think of would be to require implementation to also provide an example path to use instead of the hardcoded edit: #7356 is the proposed fix |
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',
} |
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. |
🐛 Bug Report
When using the new snapshot resolver feature: #6143, the "Obsolete" Snapshot checker is deciding that all my snapshots are obsolete after a test run.
To Reproduce
yarn test
notice all your tests pass, and snapshots are in their new location45 snapshot files obsolete from 45 test suites.
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:
The text was updated successfully, but these errors were encountered: