cy-verify-downloads
cy-verify-downloads copied to clipboard
Option "contains" don't work if the file not exist (randomBytes method not found)
Hello, Thanks for this project !
I have a question, I would check if a file was download and start by a prefix. But I need to use a timeout too.
So I combinated options like this :
cy.verifyDownload(prefix, { contains: true, timeout: 20*1000, interval: 500 });
And it not work. The contains option work, but if the file don't exist, the timeout was ignore, because the method :
const getTempName = () =>
${randomBytes(8)}-temp-file-name-${randomBytes(8)}
;
Was in error :
Thanks :)
I propose you a fix :
const resolveValue = () => {
let result;
if (contains) {
result = cy.task('findFiles', { path: downloadsFolder, fileName }).then((files) => {
let isFileExist = false;
if (files !== null && files[0]) {
if (files.length > 1)
cy.log(
`**WARNING!** More than one file found for the **'${fileName}'** pattern: [${files}] - the first one **[${files[0]}]** will be used`
);
isFileExist = cy.task('isFileExist', join(downloadsFolder, files[0]));
}
return isFileExist;
});
} else {
result = cy.task('isFileExist', downloadFileName);
}
return result.then(checkFile);
};
Add the check on 'files[0]' and don't use the randomBytes method. I try in my local env, and it work for me.
I'm seeing the same issue, which started after upgrading from node 18.17.0 to node 20.12.1. Looks like the function randomBytes
got removed after being deprecated for some time. Merging #94 would be appreciated!