`I.waitForFile` (FileSystem helper) fails if directory does not exist (yet)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript, nodejs
- Domain
- testing
Research direction
Start in lib/helper/FileSystem.js at isFileExists and trace how I.waitForFile handles a missing parent directory and its timeout cleanup. Confirm the behavior with the existing FileSystem helper coverage if available; done means waiting does not throw when the directory is initially absent and still detects the file once it appears.
Written by the indexing model from the issue text.
Description
I.waitForFile sometimes fails and throws weird exceptions if the directory containing the expected file does not exist yet.
Example (all output goes to ${codecept_dir}/output/):
I.handleDownloads('downloads/example.txt');
I.click('button.download');
I.amInPath('output/downloads');
I.waitForFile('example.txt', 5);
If the directory ${codecept_dir}/output/downloads does not exist yet (it will be created by the browser download at some point in time), the function I.waitForFile will throw an exception ReferenceError: Cannot access 'watcher' before initialization and the test will fail.
Root cause is in the function isFileExists of the FileSystem helper. The line const watcher = fs.watch(dir, (eventType, filename) => {... will throw if dir does not exist yet. This exception remains unhandled. Later, the timer for the 5sec timeout detection will try to close the uninitialized watcher, leading to the ReferenceError.
I will try to create a PR.
- Dominant language
- JavaScript
- Stars
- 4.2k
- Forks
- 756
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from codeceptjs/CodeceptJS
-
stale
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
codeceptjs/CodeceptJS#5358 · 1 comment ·
-
stale
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
codeceptjs/CodeceptJS#4958 · 10 comments · 2 reactions ·
-
stale
Difficulty 1/5 Under an hour Newbie friendliness 72/100
codeceptjs/CodeceptJS#4778 · 3 comments ·
-
stale
Difficulty 4/5 3-5 days Newbie friendliness 38/100
codeceptjs/CodeceptJS#5618 · 1 comment ·
-
stale
Difficulty 4/5 3-5 days Newbie friendliness 35/100
codeceptjs/CodeceptJS#5585 · 1 comment ·
All issues in codeceptjs/CodeceptJS
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·