From 344a2152eb963b894fca385b3dcbc9a6c60ff4c0 Mon Sep 17 00:00:00 2001 From: Sagar Ganiga Date: Thu, 16 Apr 2020 20:50:17 +0530 Subject: [PATCH 1/5] Fix circular zipping: change directory archive to glob archive --- bin/helpers/archiver.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/helpers/archiver.js b/bin/helpers/archiver.js index 2b6c2376..2bfbea1d 100644 --- a/bin/helpers/archiver.js +++ b/bin/helpers/archiver.js @@ -35,7 +35,8 @@ const archiveSpecs = (runSettings, filePath) => { archive.pipe(output); - archive.directory(cypressFolderPath, false); + let filesToIgnore = [ '*.zip', '*.mp4', '*.png', '*.jpeg', '^.' ] + archive.glob('**/*', { ignore: filesToIgnore, cwd: cypressFolderPath }); archive.finalize(); }); From 9da41eda0e8c05ef93488721305f680ac37ca2de Mon Sep 17 00:00:00 2001 From: Sagar Ganiga Date: Mon, 20 Apr 2020 14:54:22 +0530 Subject: [PATCH 2/5] Whitelist allowed extensions --- bin/helpers/archiver.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/helpers/archiver.js b/bin/helpers/archiver.js index 2bfbea1d..a011663c 100644 --- a/bin/helpers/archiver.js +++ b/bin/helpers/archiver.js @@ -35,8 +35,10 @@ const archiveSpecs = (runSettings, filePath) => { archive.pipe(output); - let filesToIgnore = [ '*.zip', '*.mp4', '*.png', '*.jpeg', '^.' ] - archive.glob('**/*', { ignore: filesToIgnore, cwd: cypressFolderPath }); + let allowedFileTypes = [ 'js', 'json', 'txt', 'ts' ] + allowedFileTypes.forEach(fileType => { + archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true }); + }); archive.finalize(); }); From d1b1beafe3a872394f05e61eeb2fcfcc825aaa5b Mon Sep 17 00:00:00 2001 From: Sagar Ganiga Date: Mon, 20 Apr 2020 15:26:08 +0530 Subject: [PATCH 3/5] Add node_modules to ignore list --- bin/helpers/archiver.js | 2 +- bin/helpers/capabilityHelper.js | 39 --------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/bin/helpers/archiver.js b/bin/helpers/archiver.js index a011663c..3f9fea9c 100644 --- a/bin/helpers/archiver.js +++ b/bin/helpers/archiver.js @@ -37,7 +37,7 @@ const archiveSpecs = (runSettings, filePath) => { let allowedFileTypes = [ 'js', 'json', 'txt', 'ts' ] allowedFileTypes.forEach(fileType => { - archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true }); + archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: 'node_modules/**' }); }); archive.finalize(); diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 2bdccd95..9c1d2fb3 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -70,49 +70,10 @@ const validate = (bsConfig) => { if(!bsConfig.run_settings.cypress_proj_dir) reject(Constants.validationMessages.EMPTY_SPEC_FILES); - if(invalidFiles(bsConfig.run_settings.cypress_proj_dir)) reject(Constants.validationMessages.INVALID_EXTENSION); - resolve(Constants.validationMessages.VALIDATED); }); } -const invalidFiles = (testFolder)=> { - var options = { - dot: true - } - files = glob.sync(testFolder + "/**/*", options) - var invalidFiles = [] - files.forEach(file => { - if(isHiddenPath(file) || invalidExtension(file)){ - invalidFiles.push(file) - } - }); - - if(invalidFiles.length > 0) { - logger.log("These files are not valid: " + invalidFiles.toString()) - return true - } else { - return false - } -} - -var isHiddenPath = (path) => { - return (/(^|\/)\.[^\/\.]/g).test(path); -}; - -var invalidExtension = (file) => { - let ext = file.split('.').pop(); - if (isFile(file) && !["js", "json", "txt"].includes(ext)) { - return true; - } - - return false; -} - -var isFile = (path) => { - return path.split('/').pop().indexOf('.') > -1; -} - module.exports = { caps, validate From 75d368eba853f1eab19a726afcf54ec53cd9990a Mon Sep 17 00:00:00 2001 From: Sagar Ganiga Date: Mon, 20 Apr 2020 15:47:21 +0530 Subject: [PATCH 4/5] Delete file in catch as well --- bin/commands/runs.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index be3d03c2..d2efb8ab 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -12,6 +12,16 @@ module.exports = function run(args) { return runCypress(args); } +function deleteZip() { + fs.unlink(config.fileName, function (err) { + if(err) { + logger.log(Constants.userMessages.ZIP_DELETE_FAILED); + } else { + logger.log(Constants.userMessages.ZIP_DELETED); + } + }); +} + function runCypress(args) { let bsConfigPath = process.cwd() + args.cf; logger.log(`Reading config from ${args.cf}`); @@ -30,25 +40,19 @@ function runCypress(args) { }).catch(function (err) { // Build creation failed logger.error(Constants.userMessages.BUILD_FAILED) - }).finally(function() { - // Delete zip file from local storage - fs.unlink(config.fileName, function (err) { - if(err) { - logger.log(Constants.userMessages.ZIP_DELETE_FAILED); - } else { - logger.log(Constants.userMessages.ZIP_DELETED); - } - }); }); }).catch(function (err) { // Zip Upload failed logger.error(err) logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED) + }).finally(function (params) { + deleteZip(); }); }).catch(function (err) { // Zipping failed logger.error(err) logger.error(Constants.userMessages.FAILED_TO_ZIP) + deleteZip(); }); }).catch(function (err) { // browerstack.json is not valid From a3c076d316485cdda2840f1fa2b5b26a6d5cb96e Mon Sep 17 00:00:00 2001 From: Sagar Ganiga Date: Mon, 20 Apr 2020 15:56:52 +0530 Subject: [PATCH 5/5] remove params from finally --- bin/commands/runs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index d2efb8ab..37a45641 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -45,7 +45,7 @@ function runCypress(args) { // Zip Upload failed logger.error(err) logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED) - }).finally(function (params) { + }).finally(function () { deleteZip(); }); }).catch(function (err) {