Skip to content

Commit 4dcd7a9

Browse files
committed
Merge branch 'master' into cypress_config_file_support
2 parents c1aed86 + 8c30b5e commit 4dcd7a9

File tree

8 files changed

+414
-2
lines changed

8 files changed

+414
-2
lines changed

bin/commands/runs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module.exports = function run(args) {
2929
// set cypress config filename
3030
utils.setCypressConfigFilename(bsConfig, args);
3131

32+
// accept the specs list from command line if provided
33+
utils.setUserSpecs(bsConfig, args);
34+
35+
// accept the env list from command line and set it
36+
utils.setTestEnvs(bsConfig, args);
37+
3238
//accept the local from env variable if provided
3339
utils.setLocal(bsConfig);
3440

bin/helpers/capabilityHelper.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ const caps = (bsConfig, zip) => {
6868
obj.projectNotifyURL = bsConfig.run_settings.project_notify_URL;
6969
obj.parallels = bsConfig.run_settings.parallels;
7070

71-
if (bsConfig.run_settings.cypress_config_filename) {
71+
if (!Utils.isUndefined(bsConfig.run_settings.cypress_config_filename)) {
7272
obj.cypress_config_filename = bsConfig.run_settings.cypress_config_filename;
7373
}
74+
75+
if (!Utils.isUndefined(bsConfig.run_settings.specs)){
76+
obj.specs = bsConfig.run_settings.specs;
77+
}
78+
79+
if (!Utils.isUndefined(bsConfig.run_settings.env)){
80+
obj.env = bsConfig.run_settings.env;
81+
}
7482
}
7583

7684
if(obj.parallels === Constants.constants.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined

bin/helpers/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ const cliMessages = {
6262
CYPRESS_DESC: "Path to Cypress config file",
6363
CONFIG_DEMAND: "config file is required",
6464
CYPRESS_CONFIG_DEMAND: "Cypress config file is required",
65-
BUILD_NAME: "The build name you want to use to name your test runs"
65+
BUILD_NAME: "The build name you want to use to name your test runs",
66+
SPECS_DESCRIPTION: 'Specify the spec files to run',
67+
ENV_DESCRIPTION: "Specify the environment variables for your spec files"
6668
},
6769
COMMON: {
6870
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/utils.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,36 @@ exports.setCypressConfigFilename = (bsConfig, args) => {
148148
bsConfig.run_settings.cypressConfigFilePath = bsConfig.run_settings.userProvidedCypessConfigFile ? bsConfig.run_settings.cypress_config_file : path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json');
149149
}
150150

151+
// specs can be passed from bstack configuration file
152+
// specs can be passed via command line args as a string
153+
// command line args takes precedence over config
154+
exports.setUserSpecs = (bsConfig, args) => {
155+
let bsConfigSpecs = bsConfig.run_settings.specs;
156+
157+
if (!this.isUndefined(args.specs)) {
158+
bsConfig.run_settings.specs = this.fixCommaSeparatedString(args.specs);
159+
} else if (!this.isUndefined(bsConfigSpecs) && Array.isArray(bsConfigSpecs)) {
160+
bsConfig.run_settings.specs = bsConfigSpecs.join(',');
161+
} else if (!this.isUndefined(bsConfigSpecs) && typeof(bsConfigSpecs) == "string") {
162+
bsConfig.run_settings.specs = this.fixCommaSeparatedString(bsConfigSpecs);
163+
} else {
164+
bsConfig.run_settings.specs = null;
165+
}
166+
}
167+
168+
// env option must be set only from command line args as a string
169+
exports.setTestEnvs = (bsConfig, args) => {
170+
if (!this.isUndefined(args.env)) {
171+
bsConfig.run_settings.env = this.fixCommaSeparatedString(args.env);
172+
} else {
173+
bsConfig.run_settings.env = null;
174+
}
175+
}
176+
177+
exports.fixCommaSeparatedString = (string) => {
178+
return string.split(/\s{0,},\s+/).join(',');
179+
}
180+
151181
exports.isUndefined = value => (value === undefined || value === null);
152182

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

bin/runner.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ var argv = yargs
174174
type: "string",
175175
default: undefined
176176
},
177+
's': {
178+
alias: ['specs', 'spec'],
179+
describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION,
180+
type: "string",
181+
default: undefined
182+
},
183+
'env': {
184+
describe: Constants.cliMessages.RUN.ENV_DESCRIPTION,
185+
type: "string",
186+
default: undefined
187+
},
177188
'disable-npm-warning': {
178189
default: false,
179190
description: Constants.cliMessages.COMMON.NO_NPM_WARNING,

test/unit/bin/commands/runs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ describe("runs", () => {
8686
setAccessKeyStub = sandbox.stub();
8787
setBuildNameStub = sandbox.stub();
8888
setCypressConfigFilenameStub = sandbox.stub();
89+
setUserSpecsStub = sandbox.stub();
90+
setTestEnvsStub = sandbox.stub();
8991
getConfigPathStub = sandbox.stub();
9092
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
9193
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -118,6 +120,8 @@ describe("runs", () => {
118120
setAccessKey: setAccessKeyStub,
119121
setBuildName: setBuildNameStub,
120122
setCypressConfigFilename: setCypressConfigFilenameStub,
123+
setUserSpecs: setUserSpecsStub,
124+
setTestEnvs: setTestEnvsStub,
121125
getConfigPath: getConfigPathStub,
122126
setLocal: setLocalStub,
123127
setLocalIdentifier: setLocalIdentifierStub,
@@ -168,6 +172,8 @@ describe("runs", () => {
168172
getConfigPathStub = sandbox.stub();
169173
setBuildNameStub = sandbox.stub();
170174
setCypressConfigFilenameStub = sandbox.stub();
175+
setUserSpecsStub = sandbox.stub();
176+
setTestEnvsStub = sandbox.stub();
171177
validateBstackJsonStub = sandbox.stub();
172178
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
173179
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -200,6 +206,8 @@ describe("runs", () => {
200206
setAccessKey: setAccessKeyStub,
201207
setBuildName: setBuildNameStub,
202208
setCypressConfigFilename: setCypressConfigFilenameStub,
209+
setUserSpecs: setUserSpecsStub,
210+
setTestEnvs: setTestEnvsStub,
203211
setUsageReportingFlag: setUsageReportingFlagStub,
204212
getConfigPath: getConfigPathStub,
205213
setLocal: setLocalStub,
@@ -260,6 +268,8 @@ describe("runs", () => {
260268
setAccessKeyStub = sandbox.stub();
261269
setBuildNameStub = sandbox.stub();
262270
setCypressConfigFilenameStub = sandbox.stub();
271+
setUserSpecsStub = sandbox.stub();
272+
setTestEnvsStub = sandbox.stub();
263273
getConfigPathStub = sandbox.stub();
264274
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
265275
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -293,6 +303,8 @@ describe("runs", () => {
293303
setAccessKey: setAccessKeyStub,
294304
setBuildName: setBuildNameStub,
295305
setCypressConfigFilename: setCypressConfigFilenameStub,
306+
setUserSpecs: setUserSpecsStub,
307+
setTestEnvs: setTestEnvsStub,
296308
setUsageReportingFlag: setUsageReportingFlagStub,
297309
getConfigPath: getConfigPathStub,
298310
setLocal: setLocalStub,
@@ -360,6 +372,8 @@ describe("runs", () => {
360372
setAccessKeyStub = sandbox.stub();
361373
setBuildNameStub = sandbox.stub();
362374
setCypressConfigFilenameStub = sandbox.stub();
375+
setUserSpecsStub = sandbox.stub();
376+
setTestEnvsStub = sandbox.stub();
363377
getConfigPathStub = sandbox.stub();
364378
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
365379
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -394,6 +408,8 @@ describe("runs", () => {
394408
setAccessKey: setAccessKeyStub,
395409
setBuildName: setBuildNameStub,
396410
setCypressConfigFilename: setCypressConfigFilenameStub,
411+
setUserSpecs: setUserSpecsStub,
412+
setTestEnvs: setTestEnvsStub,
397413
setUsageReportingFlag: setUsageReportingFlagStub,
398414
getConfigPath: getConfigPathStub,
399415
setLocal: setLocalStub,
@@ -472,6 +488,8 @@ describe("runs", () => {
472488
setAccessKeyStub = sandbox.stub();
473489
setBuildNameStub = sandbox.stub();
474490
setCypressConfigFilenameStub = sandbox.stub();
491+
setUserSpecsStub = sandbox.stub();
492+
setTestEnvsStub = sandbox.stub();
475493
getConfigPathStub = sandbox.stub();
476494
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
477495
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -509,6 +527,8 @@ describe("runs", () => {
509527
setAccessKey: setAccessKeyStub,
510528
setBuildName: setBuildNameStub,
511529
setCypressConfigFilename: setCypressConfigFilenameStub,
530+
setUserSpecs: setUserSpecsStub,
531+
setTestEnvs: setTestEnvsStub,
512532
setUsageReportingFlag: setUsageReportingFlagStub,
513533
setParallels: setParallelsStub,
514534
getConfigPath: getConfigPathStub,

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,136 @@ describe("capabilityHelper.js", () => {
249249
chai.assert.fail("Promise error");
250250
});
251251
});
252+
253+
context("specs and env from run_setting", () => {
254+
it("sets specs list is present", () => {
255+
let specsList = "spec1,spec2";
256+
let zip_url = "bs://<random>";
257+
let bsConfig = {
258+
auth: {
259+
username: "random",
260+
access_key: "random",
261+
},
262+
browsers: [
263+
{
264+
browser: "chrome",
265+
os: "Windows 10",
266+
versions: ["78", "77"],
267+
},
268+
],
269+
run_settings: {
270+
specs: specsList
271+
},
272+
};
273+
274+
return capabilityHelper
275+
.caps(bsConfig, { zip_url: zip_url })
276+
.then(function (data) {
277+
let parsed_data = JSON.parse(data);
278+
chai.assert.equal(parsed_data.specs, specsList);
279+
chai.assert.equal(parsed_data.env, undefined);
280+
})
281+
.catch((error) => {
282+
chai.assert.fail("Promise error");
283+
});
284+
});
285+
286+
it("sets env list is present", () => {
287+
let envList = "env1=value1,env2=value2";
288+
let zip_url = "bs://<random>";
289+
let bsConfig = {
290+
auth: {
291+
username: "random",
292+
access_key: "random",
293+
},
294+
browsers: [
295+
{
296+
browser: "chrome",
297+
os: "Windows 10",
298+
versions: ["78", "77"],
299+
},
300+
],
301+
run_settings: {
302+
env: envList
303+
},
304+
};
305+
306+
return capabilityHelper
307+
.caps(bsConfig, { zip_url: zip_url })
308+
.then(function (data) {
309+
let parsed_data = JSON.parse(data);
310+
chai.assert.equal(parsed_data.env, envList);
311+
chai.assert.equal(parsed_data.specs, undefined);
312+
})
313+
.catch((error) => {
314+
chai.assert.fail("Promise error");
315+
});
316+
});
317+
318+
it("sets both specs and env list is present", () => {
319+
let specsList = "spec1,spec2";
320+
let envList = "env1=value1,env2=value2";
321+
let zip_url = "bs://<random>";
322+
let bsConfig = {
323+
auth: {
324+
username: "random",
325+
access_key: "random",
326+
},
327+
browsers: [
328+
{
329+
browser: "chrome",
330+
os: "Windows 10",
331+
versions: ["78", "77"],
332+
},
333+
],
334+
run_settings: {
335+
specs: specsList,
336+
env: envList
337+
},
338+
};
339+
340+
return capabilityHelper
341+
.caps(bsConfig, { zip_url: zip_url })
342+
.then(function (data) {
343+
let parsed_data = JSON.parse(data);
344+
chai.assert.equal(parsed_data.specs, specsList);
345+
chai.assert.equal(parsed_data.env, envList);
346+
})
347+
.catch((error) => {
348+
chai.assert.fail("Promise error");
349+
});
350+
});
351+
352+
it("both specs and env list is not present", () => {
353+
let zip_url = "bs://<random>";
354+
let bsConfig = {
355+
auth: {
356+
username: "random",
357+
access_key: "random",
358+
},
359+
browsers: [
360+
{
361+
browser: "chrome",
362+
os: "Windows 10",
363+
versions: ["78", "77"],
364+
},
365+
],
366+
run_settings: {
367+
},
368+
};
369+
370+
return capabilityHelper
371+
.caps(bsConfig, { zip_url: zip_url })
372+
.then(function (data) {
373+
let parsed_data = JSON.parse(data);
374+
chai.assert.equal(parsed_data.specs, undefined);
375+
chai.assert.equal(parsed_data.env, undefined);
376+
})
377+
.catch((error) => {
378+
chai.assert.fail("Promise error");
379+
});
380+
});
381+
});
252382
});
253383

254384
describe("validate", () => {

0 commit comments

Comments
 (0)