Skip to content

Support for Custom Commands #9

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 17 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function runCypress(args) {
capabilityHelper.validate(bsConfig).then(function (validated) {
logger.log(validated);
// Archive the spec files
archiver.archive(bsConfig.run_settings.specs, config.fileName).then(function (data) {
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
// Uploaded zip file
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
// Create build
Expand Down
18 changes: 7 additions & 11 deletions bin/helpers/archiver.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

var fs = require('fs');
var archiver = require('archiver');
var request = require('request')
var config = require('./config');
var logger = require("./logger")
const fs = require('fs'),
archiver = require('archiver'),
logger = require("./logger");


const archiveSpecs = (specs, filePath) => {
const archiveSpecs = (runSettings, filePath) => {
return new Promise(function (resolve, reject) {
var output = fs.createWriteStream(filePath);

var cypressFolderPath = runSettings.cypress

var archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
Expand All @@ -36,10 +35,7 @@ const archiveSpecs = (specs, filePath) => {

archive.pipe(output);

specs.forEach(function (item, index) {
logger.log("Adding " + item + " to zip");
archive.glob(item);
});
archive.directory(cypressFolderPath, false);

archive.finalize();
});
Expand Down
46 changes: 43 additions & 3 deletions bin/helpers/capabilityHelper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var logger = require("./logger");
const Constants = require('./constants');
const logger = require("./logger"),
Constants = require('./constants'),
glob = require("glob");

const caps = (bsConfig, zip) => {
return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -67,12 +68,51 @@ const validate = (bsConfig) => {

if (!bsConfig.run_settings) reject(Constants.validationMessages.EMPTY_RUN_SETTINGS);

if(!bsConfig.run_settings.specs || bsConfig.run_settings.specs.length === 0) reject(Constants.validationMessages.EMPTY_SPEC_FILES);
if(!bsConfig.run_settings.cypress) reject(Constants.validationMessages.EMPTY_SPEC_FILES);

if(invalidFiles(bsConfig.run_settings.cypress)) 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
3 changes: 2 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const validationMessages = {
EMPTY_RUN_SETTINGS: "Empty run settings",
EMPTY_SPEC_FILES: "No spec files specified in run_settings",
VALIDATED: "browserstack.json file is validated",
NOT_VALID: "browerstack.json is not valid"
NOT_VALID: "browerstack.json is not valid",
INVALID_EXTENSION: "Invalid files, please remove these files and try again."
};
const cliMessages = {
VERSION: {
Expand Down
2 changes: 1 addition & 1 deletion bin/templates/configTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function () {
}
],
"run_settings": {
"specs": ["folder_path_with_files/*.js"],
"cypress" : "/path/to/cypress.json",
"project": "project-name",
"customBuildName": "build-name"
},
Expand Down