Make snapshot file path configurable
See original GitHub issueHey, it’s me again.
The current snapshots are saved in the relative path of the test spec file, under __snapshots__
folder. To improve the performance, we introduce an index_spec.js
to collect all test files in the same folder and run them together, now we have 2 issues:
- If run with
index_spec.js
, all snapshots are saved in oneindex_spec.js.snap
, which is not easy to track when we have many cases. - If we just run one spec file, say a_spec.file, the snapshot is generated again
a_spec.js.snap
in diff path, which will be AUTOPASS because it’s not existed before.
I have an idea: generate the file name according to the key word in the test title, but it seems annoying since we need to unify all test titles and index_spec.js
is not in common use. So I would like to hear from you, you should have better vision.
Here is my proposal code change(the test title should follow the pattern - [Filename] XXXXXX):
function getSnapshotFilename(testFile, snapshotTitle) { const dir = path.join(path.dirname(testFile), DIR_SNAPSHOTS); const filename = `${snapshotTitle.match(/\[(.+)?\]/)[1]}.snap`; return path.join(dir, filename); }
Here is the context of index_spec.js
:
const reqCont = require.context('./', true, /_spec\.js?$/); reqCont.keys().forEach(filename => reqCont(filename));
And here is our case file structure screenshot:
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
It’ll be great if we can make the path configurable so we put the image snapshots in a completely different directory
Hello, any updates on this issue? I’m trying to use
cypress-plugin-snapshots
in an Angular app and it works fine, but the actual screenshots are saved underdist/
folder where the tests are compiled from typescript into javascript. This folder is excluded from git (in.gitignore
), so the snapshots are not really part of the repository this way… How can we move the screenshots to where the tests are, so that they are pushed to git and version tracked?