diff --git a/bin/commands/runs.js b/bin/commands/runs.js index be3d03c2..37a45641 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 () { + 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 diff --git a/bin/helpers/archiver.js b/bin/helpers/archiver.js index 2b6c2376..3f9fea9c 100644 --- a/bin/helpers/archiver.js +++ b/bin/helpers/archiver.js @@ -35,7 +35,10 @@ const archiveSpecs = (runSettings, filePath) => { archive.pipe(output); - archive.directory(cypressFolderPath, false); + let allowedFileTypes = [ 'js', 'json', 'txt', 'ts' ] + allowedFileTypes.forEach(fileType => { + 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