Skip to content

Commit

Permalink
feat: delete screenshot option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrepasc committed Jul 15, 2024
1 parent 8dbc225 commit 97b667d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions cypress/e2e/matchImageSnapshot.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ it('allows .snap extension to be changed', () => {
)
})

it('allows screenshot to not be deleted', () => {
cy.get('body').matchImageSnapshot('no-delete', {
isDeleteScreenshot: false,
})

cy.readFile(
'./cypress/screenshots/matchImageSnapshot.cy.ts/no-delete.png',
).should('exist')
})

it('allows screenshot to not be deleted default', () => {
cy.get('body').matchImageSnapshot('no-delete-default')

cy.readFile(
'./cypress/screenshots/matchImageSnapshot.cy.ts/no-delete-default.png',
).should('not.exist')
})

// next two tests use blackout to change
// the snapshot image. Also validates options
it('name and options', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const defaultOptions: SnapshotOptions = {
failureThresholdType: 'pixel',
snapFilenameExtension: '.snap',
diffFilenameExtension: '.diff',
isDeleteScreenshot: true,
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ const runImageDiffAfterScreenshot = async (
}

const receivedImageBuffer = await fs.readFile(screenshotPath)
await fs.rm(screenshotPath)

if (options.isDeleteScreenshot) {
await fs.rm(screenshotPath)
}

const {
currentTestTitle,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type SnapshotOptions = {
e2eSpecDir: string
snapFilenameExtension: string
diffFilenameExtension: string
isDeleteScreenshot?: boolean
} & CypressScreenshotOptions &
MatchImageSnapshotOptions

Expand All @@ -40,6 +41,7 @@ export type CypressImageSnapshotOptions = Partial<
e2eSpecDir?: string
snapFilenameExtension?: string
diffFilenameExtension?: string
isDeleteScreenshot?: boolean
}

export type Subject =
Expand Down

0 comments on commit 97b667d

Please sign in to comment.