Skip to content

Commit d8d560d

Browse files
committed
Merge branch 'master' into cypress_config_file_support
2 parents 4dcd7a9 + 832af98 commit d8d560d

File tree

8 files changed

+99
-12
lines changed

8 files changed

+99
-12
lines changed

bin/commands/runs.js

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

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

5454
// Uploaded zip file
5555
return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
@@ -59,7 +59,7 @@ module.exports = function run(args) {
5959
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
6060
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
6161
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
62-
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)) {
62+
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)) {
6363
logger.warn(Constants.userMessages.NO_PARALLELS);
6464
}
6565

bin/helpers/archiver.js

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

44
const archiver = require("archiver"),
5+
Constants = require('../helpers/constants'),
56
logger = require("./logger").winstonLogger,
7+
utils = require('../helpers/utils'),
68
path = require('path');
79

8-
const archiveSpecs = (runSettings, filePath) => {
10+
const archiveSpecs = (runSettings, filePath, excludeFiles) => {
911
return new Promise(function (resolve, reject) {
1012
var output = fs.createWriteStream(filePath);
1113

@@ -37,9 +39,10 @@ const archiveSpecs = (runSettings, filePath) => {
3739

3840
archive.pipe(output);
3941

40-
let allowedFileTypes = [ 'js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip' ];
41-
allowedFileTypes.forEach(fileType => {
42-
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ['**/node_modules/**', './node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip', 'cypress.json'] });
42+
let ignoreFiles = getFilesToIgnore(runSettings, excludeFiles);
43+
44+
Constants.allowedFileTypes.forEach(fileType => {
45+
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles });
4346
});
4447

4548
let packageJSON = {};
@@ -68,4 +71,21 @@ const archiveSpecs = (runSettings, filePath) => {
6871
});
6972
}
7073

74+
const getFilesToIgnore = (runSettings, excludeFiles) => {
75+
let ignoreFiles = Constants.filesToIgnoreWhileUploading;
76+
77+
// exclude files asked by the user
78+
// args will take precedence over config file
79+
if (!utils.isUndefined(excludeFiles)) {
80+
let excludePatterns = utils.fixCommaSeparatedString(excludeFiles).split(',');
81+
ignoreFiles = ignoreFiles.concat(excludePatterns);
82+
logger.info(`Excluding files matching: ${JSON.stringify(excludePatterns)}`);
83+
} else if (!utils.isUndefined(runSettings.exclude) && runSettings.exclude.length) {
84+
ignoreFiles = ignoreFiles.concat(runSettings.exclude);
85+
logger.info(`Excluding files matching: ${JSON.stringify(runSettings.exclude)}`);
86+
}
87+
88+
return ignoreFiles;
89+
}
90+
7191
exports.archive = archiveSpecs

bin/helpers/capabilityHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const caps = (bsConfig, zip) => {
8181
}
8282
}
8383

84-
if(obj.parallels === Constants.constants.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
84+
if(obj.parallels === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
8585

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

bin/helpers/constants.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const cliMessages = {
6363
CONFIG_DEMAND: "config file is required",
6464
CYPRESS_CONFIG_DEMAND: "Cypress config file is required",
6565
BUILD_NAME: "The build name you want to use to name your test runs",
66+
EXCLUDE: "Exclude files matching a pattern from zipping and uploading",
67+
DEFAULT_PARALLEL_MESSAGE: "Here goes the number of parallels you want to run",
6668
SPECS_DESCRIPTION: 'Specify the spec files to run',
6769
ENV_DESCRIPTION: "Specify the environment variables for your spec files"
6870
},
@@ -83,14 +85,15 @@ const messageTypes = {
8385
NULL: null
8486
}
8587

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

9092
module.exports = Object.freeze({
9193
userMessages,
9294
cliMessages,
9395
validationMessages,
9496
messageTypes,
95-
constants
97+
allowedFileTypes,
98+
filesToIgnoreWhileUploading
9699
});

bin/helpers/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ exports.isUndefined = value => (value === undefined || value === null);
183183
exports.isFloat = value => (Number(value) && Number(value) % 1 !== 0);
184184

185185
exports.isParallelValid = (value) => {
186-
return this.isUndefined(value) || !(isNaN(value) || this.isFloat(value) || parseInt(value, 10) === 0 || parseInt(value, 10) < -1) || value === Constants.constants.DEFAULT_PARALLEL_MESSAGE;
186+
return this.isUndefined(value) || !(isNaN(value) || this.isFloat(value) || parseInt(value, 10) === 0 || parseInt(value, 10) < -1) || value === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE;
187187
}
188188

189189
exports.getUserAgent = () => {

bin/runner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ var argv = yargs
174174
type: "string",
175175
default: undefined
176176
},
177+
'e': {
178+
alias: 'exclude',
179+
describe: Constants.cliMessages.RUN.EXCLUDE,
180+
type: "string",
181+
default: undefined
182+
},
177183
's': {
178184
alias: ['specs', 'spec'],
179185
describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION,

bin/templates/configTemplate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module.exports = function () {
5555
"cypress_config_file" : "/path/to/<cypress config file>.json",
5656
"project_name": "project-name",
5757
"build_name": "build-name",
58+
"exclude": [],
5859
"parallels": "Here goes the number of parallels you want to run",
5960
"npm_dependencies": {
6061
},

test/unit/bin/helpers/archiver.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const chai = require("chai"),
2+
rewire = require("rewire"),
3+
chaiAsPromised = require("chai-as-promised");
4+
5+
const utils = require("../../../../bin/helpers/utils"),
6+
Constants = require("../../../../bin/helpers/constants"),
7+
logger = require("../../../../bin/helpers/logger").winstonLogger;
8+
9+
chai.use(chaiAsPromised);
10+
logger.transports["console.info"].silent = true;
11+
12+
const archiver = rewire("../../../../bin/helpers/archiver");
13+
14+
_getFilesToIgnore = archiver.__get__("getFilesToIgnore");
15+
16+
describe("archiver.js", () => {
17+
18+
describe("getFilesToIgnore", () => {
19+
it("no args, no exclude in runSettings", () => {
20+
chai.expect(_getFilesToIgnore({}, undefined)).to.be.eql(Constants.filesToIgnoreWhileUploading);
21+
});
22+
23+
it("args passed, no exclude in runSettings", () => {
24+
let excludeFiles = "file1.js, file2.json";
25+
let argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(',');
26+
chai.expect(_getFilesToIgnore({}, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray));
27+
28+
excludeFiles = "file1.js,file2.json";
29+
argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(',');
30+
chai.expect(_getFilesToIgnore({}, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray));
31+
32+
excludeFiles = " file1.js , file2.json ";
33+
argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(',');
34+
chai.expect(_getFilesToIgnore({}, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray));
35+
});
36+
37+
it("args passed, exclude added in runSettings", () => {
38+
// args preceed over config file
39+
let excludeFiles = "file1.js, file2.json ";
40+
let argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(',');
41+
42+
let runSettings = { exclude: [] };
43+
chai.expect(_getFilesToIgnore(runSettings, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray));
44+
45+
runSettings = { exclude: ["sample1.js", "sample2.json"] };
46+
chai.expect(_getFilesToIgnore(runSettings, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray));
47+
});
48+
49+
it("no args, exclude added in runSettings", () => {
50+
let runSettings = { exclude: [] };
51+
chai.expect(_getFilesToIgnore(runSettings, undefined)).to.be.eql(Constants.filesToIgnoreWhileUploading);
52+
53+
runSettings = { exclude: ["sample1.js", "sample2.json"] };
54+
chai.expect(_getFilesToIgnore(runSettings, undefined)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(runSettings.exclude));
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)