Skip to content

Fixed: FileSystem.waitForFile: do not crash if directory does not exist yet#5421

Open
danielrentz wants to merge 2 commits intocodeceptjs:3.xfrom
danielrentz:issue5420
Open

Fixed: FileSystem.waitForFile: do not crash if directory does not exist yet#5421
danielrentz wants to merge 2 commits intocodeceptjs:3.xfrom
danielrentz:issue5420

Conversation

@danielrentz
Copy link
Contributor

Motivation/Description of the PR

Reworked the complex implementation of FileSystem.waitForFile, now it contains a simple polling loop that uses the existing fileExists helper function like FileSystem.seeFile does.

Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium
  • TestCafe

Applicable plugins:

  • allure
  • autoDelay
  • autoLogin
  • customLocator
  • pauseOnFail
  • coverage
  • retryFailedStep
  • screenshotOnFail
  • selenoid
  • stepByStepReport
  • stepTimeout
  • wdio
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 🧹 Chore
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

throw new Error(`file (${name}) still not present in directory ${this.dir} after ${waitTimeout / 1000} sec`)
})
for (const t = Date.now() + sec * 1000; !fileExists(this.file); ) {
if (t < Date.now()) throw new Error(`file (${name}) still not present in directory ${this.dir} after ${sec} sec`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I don't understand how it works

But I agree current impleentation should be improved
Can we use while loop and some interval like 200ms to check this

And if it fails after sec seconds => throw error

Copy link
Contributor Author

@danielrentz danielrentz Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavertMik

  • The for-loop initializes t as desired timeout timestamp ("now" plus timeout seconds), and loops as long as the fie does not exist.
  • The if condition throws out of the loop if the timeout has been reached.
  • A 500ms interval delay is contained in the last line of the loop (the await new Promise).

Of course, the for loop could be rewritten as while loop to improve readability, and the interval time could be lowered to 200ms if you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed for-loop to while-loop, lowered interval to 200ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I.waitForFile (FileSystem helper) fails if directory does not exist (yet)

2 participants