Skip to content

Commit

Permalink
fix: Update default snapshot save path #29
Browse files Browse the repository at this point in the history
  • Loading branch information
alhan-garcia authored Jul 28, 2023
1 parent 4f2ea31 commit 5af993c
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 3 deletions.
9 changes: 9 additions & 0 deletions cypress/e2e/matchImageSnapshot.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ it('matches with just options', () => {
it('verify errors are stored', () => {
cy.get('body').matchImageSnapshot('error1')
cy.get('body').matchImageSnapshot('error2')
cy.get('@matchImageSnapshot').should((obj) => {
expect(Object.keys(obj).length).to.eq(2)
})
})

it('Support extra folders', () => {
cy.get('body').matchImageSnapshot('extraFolder', {
extraFolders: 'test-folder',
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const defaultOptions: SnapshotOptions = {
isUpdateSnapshots,
isSnapshotDebug,
specFileName: Cypress.spec.name,
specRelativeFolder: Cypress.spec.relative,
extraFolders: '',
currentTestTitle: '',
failureThreshold: 0,
failureThresholdType: 'pixel',
Expand Down
24 changes: 22 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const checkSnapshotExistence = ({
}) => {
const {
specFileName,
specRelativeFolder,
extraFolders,
screenshotsFolder,
isUpdateSnapshots,
customSnapshotsDir,
Expand All @@ -61,7 +63,15 @@ const checkSnapshotExistence = ({

const snapshotsDir = customSnapshotsDir
? path.join(process.cwd(), customSnapshotsDir, specFileName)
: path.join(screenshotsFolder, '..', 'snapshots', specFileName)
: path.join(
screenshotsFolder,
'..',
'snapshots',
specRelativeFolder,
'..',
extraFolders,
specFileName,
)

const snapshotDotPath = path.join(
snapshotsDir,
Expand Down Expand Up @@ -89,6 +99,8 @@ const runImageDiffAfterScreenshot = async (

const {
specFileName,
specRelativeFolder,
extraFolders,
currentTestTitle,
screenshotsFolder,
isUpdateSnapshots,
Expand All @@ -98,7 +110,15 @@ const runImageDiffAfterScreenshot = async (

const snapshotsDir = customSnapshotsDir
? path.join(process.cwd(), customSnapshotsDir, specFileName)
: path.join(screenshotsFolder, '..', 'snapshots', specFileName)
: path.join(
screenshotsFolder,
'..',
'snapshots',
specRelativeFolder,
'..',
extraFolders,
specFileName,
)

const snapshotDotPath = path.join(
snapshotsDir,
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type SnapshotOptions = {
isSnapshotDebug: boolean
specFileName: string
currentTestTitle: string
specRelativeFolder: string
} & CypressScreenshotOptions &
MatchImageSnapshotOptions &
ExtraSnapshotOptions
Expand Down Expand Up @@ -95,7 +96,12 @@ type ExtraSnapshotOptions = {
timeout: number
/**
* Sets a delay between recursive snapshots
* @default 1000.
* @default 1000
*/
delayBetweenTries: number
/**
* Adds additional folders to the snapshot save path
* @default ''
*/
extraFolders: string
}

0 comments on commit 5af993c

Please sign in to comment.