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.
I.waitForFilesometimes fails and throws weird exceptions if the directory containing the expected file does not exist yet.Example (all output goes to
${codecept_dir}/output/):If the directory
${codecept_dir}/output/downloadsdoes not exist yet (it will be created by the browser download at some point in time), the functionI.waitForFilewill throw an exceptionReferenceError: Cannot access 'watcher' before initializationand the test will fail.Root cause is in the function
isFileExistsof theFileSystemhelper. The lineconst watcher = fs.watch(dir, (eventType, filename) => {...will throw ifdirdoes not exist yet. This exception remains unhandled. Later, the timer for the 5sec timeout detection will try to close the uninitializedwatcher, leading to theReferenceError.I will try to create a PR.