From fab282d3751b2b4b7f711e314b1d43aef8fb33ab Mon Sep 17 00:00:00 2001 From: oxdev03 <140103378+oxdev03@users.noreply.github.com> Date: Thu, 2 May 2024 17:02:40 +0000 Subject: [PATCH] fix: only replace specName in cypress run mode, fixes #54 --- src/plugin.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index 6506c93..8fa2ca8 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -69,15 +69,24 @@ const runImageDiffAfterScreenshot = async ( } = options let snapshotName = path.basename(screenshotConfig.path, PNG_EXT) - const dirName = path.dirname( - screenshotConfig.path - // remove the screenshots path and just leave folders to be created in - // the snapshots folder - .replace(path.normalize(screenshotConfig.specName), '') - // remove specName here because in run mode it's added and duplicated. - // In open mode it's an empty string so is ignored - .replace(screenshotsFolder, ''), - ) + + let cleanedScreenshotPath = screenshotConfig.path + + // In open mode it's an empty string so its skipped. + if (screenshotConfig.specName) { + // remove specName here because in run mode it's added and duplicated. + cleanedScreenshotPath = cleanedScreenshotPath.replace( + path.normalize(screenshotConfig.specName), + '', + ) + } + + // remove the screenshots path and just leave folders to be created in + // the snapshots folder + cleanedScreenshotPath = cleanedScreenshotPath.replace(screenshotsFolder, '') + + const dirName = path.dirname(cleanedScreenshotPath) + snapshotName = path .join(dirName, snapshotName) .replace(/ \(attempt [0-9]+\)/, '')