From a3633c8465eaec7921f3bcd99f003b10b2b12244 Mon Sep 17 00:00:00 2001 From: Yevhen Laichenkov Date: Wed, 14 Sep 2022 13:38:48 +0300 Subject: [PATCH] update(lib): add additional check for downloaded file --- cypress/e2e/verify-download.cy.js | 7 +++++++ src/index.js | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/verify-download.cy.js b/cypress/e2e/verify-download.cy.js index b8a1974..a6f38bb 100644 --- a/cypress/e2e/verify-download.cy.js +++ b/cypress/e2e/verify-download.cy.js @@ -21,4 +21,11 @@ describe('verify download functionality', () => { cy.verifyDownload('large-file-100MB', { contains: true }); }); + + it('downloads file with extension and contains option', () => { + cy.exec(`rm -rf ${Cypress.config('downloadsFolder')}`); + cy.get('[data-cy="large"]').click(); + + cy.verifyDownload('large-file-100MB.zip', { contains: true }); + }); }); diff --git a/src/index.js b/src/index.js index 874b60c..e644285 100644 --- a/src/index.js +++ b/src/index.js @@ -70,9 +70,11 @@ const isFileExist = (path) => existsSync(path); const findFiles = ({ path, fileName }) => { if (!existsSync(path)) return null; - return readdirSync(path).filter((file) => file.includes(fileName)); + return readdirSync(path).filter((file) => file.includes(fileName) && isDownloaded(file)); }; +const isDownloaded = (file) => !file.endsWith('.crdownload'); + module.exports = { isFileExist, findFiles,