Skip to content

Commit

Permalink
fix: remove waiting time (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
alhan-garcia authored Jun 15, 2023
1 parent 5f58502 commit 782c4c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
29 changes: 1 addition & 28 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const defaultOptions: SnapshotOptions = {
currentTestTitle: '',
failureThreshold: 0,
failureThresholdType: 'pixel',
delay: 2500,
recursiveTimeout: 5000,
delayBetweenTries: 2000,
}
Expand Down Expand Up @@ -72,39 +71,13 @@ const matchImageSnapshot =

const screenshotName = getScreenshotFilename(filename)

const {specFileName, screenshotsFolder, customSnapshotsDir} = options

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

const snapshotDotPath = path.join(
snapshotsDir,
`${screenshotName}${SNAP_EXT}`,
)

const fullSnapshotPath = path.join(
replaceSlashes(screenshotsFolder),
'..',
snapshotDotPath,
)

function recursiveSnapshot():
| Cypress.Chainable<DiffSnapshotResult>
| Cypress.Chainable<DiffSnapshotResult | Cypress.Chainable<any>> {
const currentTime = Date.now()
const hasTimedOut = currentTime - startTime >= options.recursiveTimeout

cy.task('readFileMaybe', fullSnapshotPath).then((doesExist) => {
if (doesExist) {
elementToScreenshot.screenshot(screenshotName, options)
} else {
cy.wait(options.delay).then(() => {
elementToScreenshot.screenshot(screenshotName, options)
})
}
})

elementToScreenshot.screenshot(screenshotName, options)
return cy.task<DiffSnapshotResult>(RECORD).then((snapshotResult) => {
const {
added,
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ type ExtraSnapshotOptions = {
* Waits an arbitrary amount of time (in milliseconds) if the baseline image doesn't exist
* @default 2500
*/
delay: number
//TODO: Implement waiting if reference image doesn't exist :)
//delay: number
/**
* Time it takes for the snapshot command to time out if the snapshot is not correct
* @default 5000
Expand Down

0 comments on commit 782c4c4

Please sign in to comment.