cypress
cypress copied to clipboard
Add support to get downloaded file when its name is not known.
It would be useful to have an option to parse downloaded files when their name is not known at the moment of download. I tried to create a helper function (task) for that which returns the latest file, however, it's not reliable as it's executed when file is not there yet:
// plugins/index.js
const getLastDownloadFilePath = () => {
const dirPath = 'cypress/downloads';
const filesOrdered = readdirSync(dirPath)
.map(entry => path.join(dirPath, entry))
.filter(entryWithPath => lstatSync(entryWithPath).isFile())
.map(fileName => ({ fileName, mtime: lstatSync(fileName).mtime }))
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
return filesOrdered.length ? filesOrdered[0].fileName : false;
};
I believe it may be useful to have the ability to:
- wait for file download,
- get the name of the downloaded file.
These two should allow handling such cases.