Skip to content

Commit c3aed35

Browse files
committed
Merge branch 'HST_722_ats' of github.com:browserstack/browserstack-cypress-cli into HST_722_ats
2 parents 4903087 + 4c0ccb6 commit c3aed35

File tree

13 files changed

+1032
-226
lines changed

13 files changed

+1032
-226
lines changed

bin/commands/runs.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ module.exports = function run(args, rawArgs) {
114114
/*
115115
Send build start to Observability
116116
*/
117-
if(isTestObservabilitySession) await launchTestSession(bsConfig, bsConfigPath);
117+
if(isTestObservabilitySession) {
118+
await launchTestSession(bsConfig, bsConfigPath);
119+
utils.setO11yProcessHooks(null, bsConfig, args, null, buildReportData);
120+
}
118121

119122
// accept the system env list from bsconf and set it
120123
utils.setSystemEnvs(bsConfig);
@@ -212,7 +215,7 @@ module.exports = function run(args, rawArgs) {
212215
let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressConfigFile, turboScaleSession);
213216
markBlockEnd('getNumberOfSpecFiles');
214217

215-
bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressConfigFile);
218+
bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressConfigFile, bsConfig);
216219

217220
// return the number of parallels user specified
218221
let userSpecifiedParallels = utils.getParallels(bsConfig, args);
@@ -279,6 +282,14 @@ module.exports = function run(args, rawArgs) {
279282
atsFileCleanup(bsConfig);
280283
}
281284

285+
// Set config args for enforce_settings
286+
if ( !utils.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) ) {
287+
markBlockStart('setEnforceSettingsConfig');
288+
logger.debug('Started setting the configs');
289+
utils.setEnforceSettingsConfig(bsConfig);
290+
logger.debug('Completed setting the configs');
291+
markBlockEnd('setEnforceSettingsConfig');
292+
}
282293
// Create build
283294
//setup Local Testing
284295
markBlockStart('localSetup');
@@ -295,6 +306,9 @@ module.exports = function run(args, rawArgs) {
295306
markBlockEnd('createBuild');
296307
markBlockEnd('total');
297308
utils.setProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData);
309+
if(isTestObservabilitySession) {
310+
utils.setO11yProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData);
311+
}
298312
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
299313
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
300314
buildReportData = { 'build_id': data.build_id, 'parallels': userSpecifiedParallels, ...buildReportData }

bin/helpers/capabilityHelper.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ const validate = (bsConfig, args) => {
184184
reject(Constants.validationMessages.EMPTY_CYPRESS_CONFIG_FILE);
185185
}
186186

187+
if ( bsConfig && bsConfig.run_settings && bsConfig.run_settings.enforce_settings && bsConfig.run_settings.enforce_settings.toString() === 'true' && Utils.isUndefined(bsConfig.run_settings.specs) ) {
188+
reject(Constants.validationMessages.EMPTY_SPECS_IN_BROWSERSTACK_JSON);
189+
}
190+
187191
// validate parallels specified in browserstack.json if parallels are not specified via arguments
188192
if (!Utils.isUndefined(args) && Utils.isUndefined(args.parallels) && !Utils.isParallelValid(bsConfig.run_settings.parallels)) reject(Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION);
189193

@@ -214,7 +218,8 @@ const validate = (bsConfig, args) => {
214218

215219
logger.debug(`Validating ${bsConfig.run_settings.cypress_config_filename}`);
216220
try {
217-
if (bsConfig.run_settings.cypress_config_filename !== 'false') {
221+
// Not reading cypress config file upon enforce_settings
222+
if (Utils.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) && bsConfig.run_settings.cypress_config_filename !== 'false') {
218223
if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
219224
const completeCypressConfigFile = readCypressConfigFile(bsConfig)
220225
if (!Utils.isUndefined(completeCypressConfigFile)) {
@@ -234,6 +239,11 @@ const validate = (bsConfig, args) => {
234239
// Detect if the user is not using the right directory structure, and throw an error
235240
if (!Utils.isUndefined(cypressConfigFile.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,cypressConfigFile.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
236241
}
242+
else {
243+
logger.debug("Validating baseurl and integrationFolder in browserstack.json");
244+
if (!Utils.isUndefined(bsConfig.run_settings.baseUrl) && bsConfig.run_settings.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", bsConfig.run_settings.baseUrl));
245+
if (!Utils.isUndefined(bsConfig.run_settings.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,bsConfig.run_settings.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
246+
}
237247
} catch(error){
238248
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
239249
}

bin/helpers/constants.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const userMessages = {
7272
UPLOADING_NPM_PACKAGES_SUCCESS: "Uploaded node_modules successfully",
7373
SKIP_UPLOADING_TESTS:
7474
"Skipping zip upload since BrowserStack already has your test suite that has not changed since the last run.",
75+
SKIP_NPM_INSTALL:
76+
"Skipping NPM Install as the enforce_settings has been passed.",
7577
SKIP_UPLOADING_NPM_PACKAGES:
7678
"Skipping the upload of node_modules since BrowserStack has already cached your npm dependencies that have not changed since the last run.",
7779
LOCAL_TRUE: "you will now be able to test localhost / private URLs",
@@ -134,8 +136,10 @@ const validationMessages = {
134136
"cypress_proj_dir is not set in run_settings. See https://www.browserstack.com/docs/automate/cypress/sample-tutorial to learn more.",
135137
EMPTY_CYPRESS_CONFIG_FILE:
136138
"cypress_config_file is not set in run_settings. See https://www.browserstack.com/docs/automate/cypress/configuration-file to learn more.",
139+
EMPTY_SPECS_IN_BROWSERSTACK_JSON:
140+
"specs is required when enforce_settings is true in run_settings of browserstack.json",
137141
VALIDATED: "browserstack.json file is validated",
138-
NOT_VALID: "browerstack.json is not valid",
142+
NOT_VALID: "browserstack.json is not valid",
139143
NOT_VALID_JSON: "browerstack.json is not a valid json",
140144
INVALID_EXTENSION: "Invalid files, please remove these files and try again.",
141145
INVALID_PARALLELS_CONFIGURATION:

bin/helpers/packageInstaller.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ const packageSetupAndInstaller = (bsConfig, packageDir, instrumentBlocks) => {
133133
let obj = {
134134
packagesInstalled: false
135135
};
136-
136+
if (bsConfig && bsConfig.run_settings && bsConfig.run_settings.enforce_settings && bsConfig.run_settings.enforce_settings.toString() === 'true' ) {
137+
logger.info("Enforce_settings is enabled in run_settings");
138+
logger.debug(Constants.userMessages.SKIP_NPM_INSTALL);
139+
return resolve(obj);
140+
}
137141
logger.info(Constants.userMessages.NPM_INSTALL);
138142
instrumentBlocks.markBlockStart("packageInstaller.folderSetup");
139143
logger.debug("Started setting up package folder");

bin/helpers/runnerArgs.js

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
const Constants = require('./constants');
2+
3+
const usernameOptions = {
4+
'u': {
5+
alias: 'username',
6+
describe: Constants.cliMessages.COMMON.USERNAME,
7+
type: "string",
8+
default: undefined
9+
},
10+
}
11+
12+
const accessKeyOptions = {
13+
'k': {
14+
alias: 'key',
15+
describe: Constants.cliMessages.COMMON.ACCESS_KEY,
16+
type: "string",
17+
default: undefined
18+
},
19+
}
20+
21+
const configFileOptions = {
22+
'cf': {
23+
alias: 'config-file',
24+
describe: Constants.cliMessages.COMMON.CONFIG_FILE_PATH,
25+
default: 'browserstack.json',
26+
type: 'string',
27+
nargs: 1,
28+
demand: true,
29+
demand: Constants.cliMessages.COMMON.CONFIG_DEMAND
30+
},
31+
}
32+
33+
const debugModeOptions = {
34+
'cli-debug': {
35+
default: false,
36+
describe: Constants.cliMessages.COMMON.DEBUG,
37+
type: "boolean"
38+
},
39+
}
40+
41+
exports.disableUsageReportingOptions = {
42+
'disable-usage-reporting': {
43+
default: undefined,
44+
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
45+
type: "boolean"
46+
},
47+
}
48+
49+
exports.commonBuildOptions = {
50+
...configFileOptions,
51+
...this.disableUsageReportingOptions,
52+
...usernameOptions,
53+
...accessKeyOptions,
54+
...debugModeOptions,
55+
}
56+
57+
exports.runOptions = {
58+
...this.commonBuildOptions,
59+
'ccf': {
60+
alias: 'cypress-config-file',
61+
describe: Constants.cliMessages.RUN.CYPRESS_DESC,
62+
default: './cypress.json',
63+
type: 'string',
64+
nargs: 1,
65+
demand: true,
66+
demand: Constants.cliMessages.RUN.CYPRESS_CONFIG_DEMAND
67+
},
68+
'gl': {
69+
alias: 'geolocation',
70+
describe: Constants.cliMessages.RUN.CYPRESS_GEO_LOCATION,
71+
default: undefined,
72+
type: 'string'
73+
},
74+
'p': {
75+
alias: ['parallels', 'parallel'],
76+
describe: Constants.cliMessages.RUN.PARALLEL_DESC,
77+
type: "number",
78+
default: undefined
79+
},
80+
'b': {
81+
alias: ['build-name', 'ci-build-id'],
82+
describe: Constants.cliMessages.RUN.BUILD_NAME,
83+
type: "string",
84+
default: undefined
85+
},
86+
'e': {
87+
alias: 'exclude',
88+
describe: Constants.cliMessages.RUN.EXCLUDE,
89+
type: "string",
90+
default: undefined
91+
},
92+
's': {
93+
alias: ['specs', 'spec'],
94+
describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION,
95+
type: "string",
96+
default: undefined
97+
},
98+
'env': {
99+
describe: Constants.cliMessages.RUN.ENV_DESCRIPTION,
100+
type: "string",
101+
default: undefined
102+
},
103+
't': {
104+
alias: ['specTimeout'],
105+
default: undefined,
106+
describe: Constants.cliMessages.RUN.SPEC_TIMEOUT,
107+
type: "string"
108+
},
109+
'disable-npm-warning': {
110+
default: false,
111+
description: Constants.cliMessages.COMMON.NO_NPM_WARNING,
112+
type: "boolean"
113+
},
114+
'sync': {
115+
default: true,
116+
describe: Constants.cliMessages.RUN.SYNC_DESCRIPTION,
117+
type: "boolean"
118+
},
119+
'async': {
120+
default: false,
121+
describe: Constants.cliMessages.RUN.ASYNC_DESCRIPTION,
122+
type: "boolean"
123+
},
124+
'force-upload': {
125+
default: false,
126+
describe: Constants.cliMessages.COMMON.FORCE_UPLOAD,
127+
type: "boolean"
128+
},
129+
'headed': {
130+
default: false,
131+
describe: Constants.cliMessages.RUN.HEADED,
132+
type: "boolean"
133+
},
134+
'local': {
135+
describe: Constants.cliMessages.RUN.LOCAL,
136+
type: "boolean"
137+
},
138+
'local-identifier': {
139+
describe: Constants.cliMessages.RUN.LOCAL_IDENTIFIER,
140+
type: "string"
141+
},
142+
'local-mode': {
143+
describe: Constants.cliMessages.RUN.LOCAL_MODE,
144+
type: "string"
145+
},
146+
'local-config-file': {
147+
describe: Constants.cliMessages.RUN.LOCAL_CONFIG_FILE,
148+
type: "string"
149+
},
150+
'no-wrap': {
151+
default: false,
152+
describe: Constants.cliMessages.RUN.SYNC_NO_WRAP,
153+
type: "boolean"
154+
},
155+
'browser': {
156+
describe: Constants.cliMessages.RUN.BROWSER_DESCRIPTION,
157+
type: "string",
158+
default: undefined
159+
},
160+
'c': {
161+
alias: 'config',
162+
describe: Constants.cliMessages.RUN.CONFIG_DESCRIPTION,
163+
type: "string",
164+
default: undefined
165+
},
166+
'r': {
167+
alias: 'reporter',
168+
default: undefined,
169+
describe: Constants.cliMessages.RUN.REPORTER,
170+
type: "string"
171+
},
172+
'o': {
173+
alias: 'reporter-options',
174+
default: undefined,
175+
describe: Constants.cliMessages.RUN.REPORTER_OPTIONS,
176+
type: "string"
177+
},
178+
'record': {
179+
describe: Constants.cliMessages.RUN.RECORD,
180+
type: "boolean"
181+
},
182+
'record-key': {
183+
default: undefined,
184+
describe: Constants.cliMessages.RUN.RECORD_KEY,
185+
type: "string"
186+
},
187+
'projectId': {
188+
default: undefined,
189+
describe: Constants.cliMessages.RUN.PROJECT_ID,
190+
type: "string"
191+
},
192+
'nv': {
193+
alias: ['node-version', 'nodeVersion'],
194+
default: undefined,
195+
describe: Constants.cliMessages.RUN.NODE_VERSION,
196+
type: "string"
197+
},
198+
'build-tag': {
199+
default: undefined,
200+
describe: Constants.cliMessages.RUN.BUILD_TAG,
201+
type: "string"
202+
}
203+
}

0 commit comments

Comments
 (0)