Skip to content

Commit

Permalink
update(lib): omit destructuring to make it work in vite
Browse files Browse the repository at this point in the history
  • Loading branch information
elaichenkov committed Sep 8, 2023
1 parent 7793447 commit e5c0af6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<a data-cy="small" href="./assets/small-file-10MB.zip" download>Download small file</a>
<br/>
<a data-cy="large" href="./assets/large-file-100MB.zip" download>Download large file</a>

</body>
</html>
22 changes: 11 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { join } = require('path');
const { existsSync, readdirSync } = require('fs');
const { randomBytes } = require('crypto');
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');

const addCustomCommand = () => {
Cypress.Commands.add('verifyDownload', (fileName, options) => {
Expand All @@ -18,7 +18,7 @@ const addCustomCommand = () => {
const { timeout, interval, contains } = { ...defaultOptions, ...options };

const downloadsFolder = Cypress.config('downloadsFolder');
const downloadFileName = join(downloadsFolder, fileName);
const downloadFileName = path.join(downloadsFolder, fileName);

let retries = Math.floor(timeout / interval);

Expand All @@ -27,7 +27,7 @@ const addCustomCommand = () => {

if (retries < 1) {
throw new Error(
`Failed after ${timeout} time out. \nDue to couldn't find ${fileName} file in the ${downloadsFolder} folder`
`Failed after ${timeout} time out. \nDue to couldn't find ${fileName} file in the ${downloadsFolder} folder`,
);
}
cy.wait(interval, { log: false }).then(() => {
Expand All @@ -44,12 +44,12 @@ const addCustomCommand = () => {
if (files !== null) {
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`
`**WARNING!** More than one file found for the **'${fileName}'** pattern: [${files}] - the first one **[${files[0]}]** will be used`,
);

const getTempName = () => `${randomBytes(8)}-temp-file-name-${randomBytes(8)}`;
const getTempName = () => `${crypto.randomBytes(8)}-temp-file-name-${crypto.randomBytes(8)}`;

return cy.task('isFileExist', join(downloadsFolder, files[0] || getTempName()));
return cy.task('isFileExist', path.join(downloadsFolder, files[0] || getTempName()));
}
});
} else {
Expand All @@ -65,12 +65,12 @@ const addCustomCommand = () => {
});
};

const isFileExist = (path) => existsSync(path);
const isFileExist = (path) => fs.existsSync(path);

const findFiles = ({ path, fileName }) => {
if (!existsSync(path)) return null;
if (!fs.existsSync(path)) return null;

return readdirSync(path).filter((file) => file.includes(fileName) && isDownloaded(file));
return fs.readdirSync(path).filter((file) => file.includes(fileName) && isDownloaded(file));
};

const isDownloaded = (file) => !file.endsWith('.crdownload');
Expand Down

0 comments on commit e5c0af6

Please sign in to comment.