diff --git a/site/index.html b/site/index.html index 281c424..e452982 100644 --- a/site/index.html +++ b/site/index.html @@ -7,5 +7,6 @@ Download small file
Download large file + \ No newline at end of file diff --git a/src/index.js b/src/index.js index f1caa75..b7fa0b2 100644 --- a/src/index.js +++ b/src/index.js @@ -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) => { @@ -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); @@ -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(() => { @@ -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 { @@ -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');