Skip to content

Commit f14aafc

Browse files
committed
fix: makes getScreenshotPath idempotent
1 parent cead779 commit f14aafc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

.changeset/nasty-nails-bow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"quickpickle": minor
3+
---
4+
5+
- Made the VisualWorld.getScreenshotPath method idempotent
6+
- Added projectRoot getter to QuickPickleWorld

packages/main/src/world.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class QuickPickleWorld implements QuickPickleWorldInterface {
6363
get config() { return this.info.config }
6464
get worldConfig() { return this.info.config.worldConfig }
6565
get isComplete() { return this.info.stepIdx === this.info.steps.length }
66+
get projectRoot() { return this._projectRoot }
6667
/**
6768
* Checks the tags of the Scenario against a provided list of tags,
6869
* and returns the shared tags, with the "@" prefix character.
@@ -327,8 +328,25 @@ export class VisualWorld extends QuickPickleWorld implements StubVisualWorldInte
327328

328329
getScreenshotPath(name?:string) {
329330
if (!name) return this.screenshotPath
331+
332+
// If name is already a full absolute path (starts with project root), return as-is
333+
if (name.startsWith(this.projectRoot)) {
334+
return name
335+
}
336+
337+
// If name starts with the screenshot directory, remove it
338+
else if (name.startsWith(this.screenshotDir)) name = name.slice(this.screenshotDir.length)
339+
340+
// If name already ends with .png, remove it
341+
const hasExtension = name.endsWith('.png')
342+
const baseName = hasExtension ? name.slice(0, -4) : name
343+
344+
// Add the exploded tags if necessary
330345
let explodedTags = this.info.explodedIdx ? `_(${this.info.tags.join(',')})` : ''
331-
return this.fullPath(`${this.screenshotDir}/${name}${explodedTags}.png`)
346+
if (name.includes(explodedTags)) explodedTags = ''
347+
348+
// Return the full path
349+
return this.fullPath(`${this.screenshotDir}/${baseName}${explodedTags}.png`)
332350
}
333351

334352
async screenshotDiff(actual:Buffer, expected:Buffer, opts:any): Promise<VisualDiffResult> {

0 commit comments

Comments
 (0)