Fixed: FileSystem.waitForFile: do not crash if directory does not exist yet#5421
Open
danielrentz wants to merge 2 commits intocodeceptjs:3.xfrom
Open
Fixed: FileSystem.waitForFile: do not crash if directory does not exist yet#5421danielrentz wants to merge 2 commits intocodeceptjs:3.xfrom
danielrentz wants to merge 2 commits intocodeceptjs:3.xfrom
Conversation
DavertMik
requested changes
Feb 8, 2026
lib/helper/FileSystem.js
Outdated
| 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`) |
Contributor
There was a problem hiding this comment.
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
Contributor
Author
There was a problem hiding this comment.
- The
for-loop initializestas 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.
Contributor
Author
There was a problem hiding this comment.
Done. Changed for-loop to while-loop, lowered interval to 200ms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation/Description of the PR
I.waitForFile(FileSystem helper) fails if directory does not exist (yet) #5420Reworked the complex implementation of
FileSystem.waitForFile, now it contains a simple polling loop that uses the existingfileExistshelper function likeFileSystem.seeFiledoes.Applicable helpers:
Applicable plugins:
Type of change
Checklist:
npm run docs)npm run lint)npm test)