Skip to content

[CYP-97] Fix for bug in zipping directory #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion bin/helpers/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
39 changes: 0 additions & 39 deletions bin/helpers/capabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down