Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RachelDSS opened this issue Mar 3, 2023 · 2 comments

Comments

@RachelDSS
Copy link

RachelDSS commented Mar 3, 2023

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 RachelDSS changed the title Combination of options "contains" and "timeout" Option "contains" don't work if the file not exist (randomBytes method not found) Mar 6, 2023
@RachelDSS
Copy link
Author

RachelDSS commented Mar 6, 2023

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.

@davidmstirn
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants