Skip to content

Commit

Permalink
[cypress-v10] Fix snapshot file location different in open vs run
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonpage committed Aug 2, 2022
1 parent a86d3b6 commit f621ff6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export function matchImageSnapshotCommand(defaultOptions) {
};

cy.task(MATCH, {
// eg. `cypress/integration/myDir/mySpec.js
specFileRelativeToRoot: Cypress.spec.relative,
screenshotsFolder,
updateSnapshots,
options,
Expand Down
15 changes: 8 additions & 7 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export function matchImageSnapshotPlugin({ path: screenshotPath }) {
const {
screenshotsFolder,
updateSnapshots,
specFileRelativeToRoot,

options: {
failureThreshold = 0,
failureThresholdType = 'pixel',
Expand All @@ -69,30 +71,29 @@ export function matchImageSnapshotPlugin({ path: screenshotPath }) {
const receivedImageBuffer = fs.readFileSync(screenshotPath);
fs.removeSync(screenshotPath);

const { dir: screenshotDir, name } = path.parse(
screenshotPath
);
const { name } = path.parse(screenshotPath);

// remove the cypress v5+ native retries suffix from the file name
const snapshotIdentifier = name.replace(/ \(attempt [0-9]+\)/, '');

const relativePath = path.relative(screenshotsFolder, screenshotDir);
const snapshotsDir = customSnapshotsDir
? path.join(process.cwd(), customSnapshotsDir, relativePath)
: path.join(screenshotsFolder, '..', 'snapshots', relativePath);
? path.join(process.cwd(), customSnapshotsDir, specFileRelativeToRoot)
: path.join(screenshotsFolder, '..', 'snapshots', specFileRelativeToRoot);

const snapshotKebabPath = path.join(
snapshotsDir,
`${snapshotIdentifier}${kebabSnap}`
);

const snapshotDotPath = path.join(
snapshotsDir,
`${snapshotIdentifier}${dotSnap}`
);

const diffDir = customDiffDir
? path.join(process.cwd(), customDiffDir, relativePath)
? path.join(process.cwd(), customDiffDir, specFileRelativeToRoot)
: path.join(snapshotsDir, '__diff_output__');

const diffDotPath = path.join(diffDir, `${snapshotIdentifier}${dotDiff}`);

if (fs.pathExistsSync(snapshotDotPath)) {
Expand Down

0 comments on commit f621ff6

Please sign in to comment.