Skip to content

Commit 5f5e845

Browse files
committed
Support for excluding files & folders from uploads
1 parent 356d9ce commit 5f5e845

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function run(args) {
3434
utils.setParallels(bsConfig, args);
3535

3636
// Archive the spec files
37-
return archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
37+
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude).then(function (data) {
3838

3939
// Uploaded zip file
4040
return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
@@ -44,7 +44,7 @@ module.exports = function run(args) {
4444
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
4545
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
4646
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
47-
if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.constants.DEFAULT_PARALLEL_MESSAGE)) {
47+
if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) {
4848
logger.warn(Constants.userMessages.NO_PARALLELS);
4949
}
5050

bin/helpers/archiver.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
const fs = require("fs");
33

44
const archiver = require("archiver"),
5+
Constants = require('../helpers/constants'),
56
logger = require("./logger").winstonLogger;
67

7-
const archiveSpecs = (runSettings, filePath) => {
8+
const archiveSpecs = (runSettings, filePath, excludeFiles) => {
89
return new Promise(function (resolve, reject) {
910
var output = fs.createWriteStream(filePath);
1011

@@ -36,9 +37,18 @@ const archiveSpecs = (runSettings, filePath) => {
3637

3738
archive.pipe(output);
3839

39-
let allowedFileTypes = [ 'js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip' ];
40-
allowedFileTypes.forEach(fileType => {
41-
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ['**/node_modules/**', './node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip'] });
40+
let ignoreFiles = Constants.filesToIgnoreWhileUploading;
41+
42+
// exclude files asked by the user
43+
// args will take precedence over config file
44+
if (!Utils.isUndefined(excludeFiles)) {
45+
ignoreFiles = ignoreFile.concat(Utils.fixCommaSeparatedString(excludeFiles).split(','));
46+
} else if (!Utils.isUndefined(runSettings.exclude)) {
47+
ignoreFiles = ignoreFile.concat(excludeFiles);
48+
}
49+
50+
Constants.allowedFileTypes.forEach(fileType => {
51+
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles });
4252
});
4353

4454
let packageJSON = {};

bin/helpers/capabilityHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const caps = (bsConfig, zip) => {
6969
obj.parallels = bsConfig.run_settings.parallels;
7070
}
7171

72-
if(obj.parallels === Constants.constants.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
72+
if(obj.parallels === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
7373

7474
if (obj.project) logger.log(`Project name is: ${obj.project}`);
7575

bin/helpers/constants.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ const cliMessages = {
6060
INFO: "Run your tests on BrowserStack.",
6161
DESC: "Path to BrowserStack config",
6262
CONFIG_DEMAND: "config file is required",
63-
BUILD_NAME: "The build name you want to use to name your test runs"
63+
BUILD_NAME: "The build name you want to use to name your test runs",
64+
EXCLUDE: "Exclude files matching a pattern from zipping and uploading",
65+
DEFAULT_PARALLEL_MESSAGE: "Here goes the number of parallels you want to run"
6466
},
6567
COMMON: {
6668
DISABLE_USAGE_REPORTING: "Disable usage reporting",
@@ -79,14 +81,15 @@ const messageTypes = {
7981
NULL: null
8082
}
8183

82-
const constants = {
83-
DEFAULT_PARALLEL_MESSAGE: "Here goes the number of parallels you want to run"
84-
}
84+
const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip'];
85+
86+
const filesToIgnoreWhileUploading = ['node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip']
8587

8688
module.exports = Object.freeze({
8789
userMessages,
8890
cliMessages,
8991
validationMessages,
9092
messageTypes,
91-
constants
93+
allowedFileTypes,
94+
filesToIgnoreWhileUploading
9295
});

bin/helpers/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,16 @@ exports.setBuildName = (bsConfig, args) => {
111111
}
112112
}
113113

114+
exports.fixCommaSeparatedString = (string) => {
115+
return string.split(/\s{0,},\s+/).join(',');
116+
}
117+
114118
exports.isUndefined = value => (value === undefined || value === null);
115119

116120
exports.isFloat = value => (Number(value) && Number(value) % 1 !== 0);
117121

118122
exports.isParallelValid = (value) => {
119-
return this.isUndefined(value) || !(isNaN(value) || this.isFloat(value) || parseInt(value, 10) === 0 || parseInt(value, 10) < -1 ) || value === Constants.constants.DEFAULT_PARALLEL_MESSAGE;
123+
return this.isUndefined(value) || !(isNaN(value) || this.isFloat(value) || parseInt(value, 10) === 0 || parseInt(value, 10) < -1 ) || value === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE;
120124
}
121125

122126
exports.getUserAgent = () => {

bin/runner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ var argv = yargs
165165
type: "string",
166166
default: undefined
167167
},
168+
'e': {
169+
alias: 'exclude',
170+
describe: Constants.cliMessages.RUN.EXCLUDE,
171+
type: "string",
172+
default: undefined
173+
},
168174
'disable-npm-warning': {
169175
default: false,
170176
description: Constants.cliMessages.COMMON.NO_NPM_WARNING,

0 commit comments

Comments
 (0)