cy-verify-downloads icon indicating copy to clipboard operation
cy-verify-downloads copied to clipboard

Option "contains" don't work if the file not exist (randomBytes method not found)

Open RachelDSS opened this issue 1 year ago • 2 comments

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 : image

Thanks :)

RachelDSS avatar Mar 03 '23 15:03 RachelDSS

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.

RachelDSS avatar Mar 06 '23 16:03 RachelDSS

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!

davidmstirn avatar Apr 05 '24 19:04 davidmstirn