Skip to content

Commit 25a7b41

Browse files
committed
Adding config template with cypress dependencies as key in browserstack.json
Removed package.json key dependency. Added config update command to update browserstack.json gracefully.
1 parent de1ee12 commit 25a7b41

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

bin/commands/updateConfig.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
var config = require('../helpers/config');
3+
var request = require('request')
4+
var logger = require("../helpers/logger");
5+
var Constants = require("../helpers/constants")
6+
var fileHelpers = require('../helpers/fileHelpers');
7+
var capabilityHelper = require("../helpers/capabilityHelper");
8+
9+
10+
let updateConfig = function(args) {
11+
let bsConfigPath = process.cwd() + args.cf;
12+
logger.log(`Updating config from ${args.cf}`);
13+
14+
var currentConfig = require(bsConfigPath);
15+
16+
var configTemplate = require('../templates/configTemplate')()
17+
var newConfig = JSON.parse(configTemplate);
18+
19+
function allDone() {
20+
logger.log(Constants.userMessages.CONFIG_FILE_CREATED);
21+
}
22+
23+
capabilityHelper.validate(currentConfig).then(function (validatedConfig) {
24+
logger.log(`${currentConfig}`);
25+
26+
for (const key in newConfig) {
27+
if (currentConfig[key] === undefined) {
28+
currentConfig[key] = newConfig[key]
29+
}
30+
}
31+
32+
var EOL = require('os').EOL
33+
var file = [
34+
JSON.stringify(currentConfig, null, 4)
35+
].join(EOL)
36+
37+
var config = {
38+
file: file,
39+
path: bsConfigPath
40+
};
41+
42+
fileHelpers.write(config, null, allDone);
43+
});
44+
}
45+
46+
module.exports = updateConfig;

bin/helpers/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ const cliMessages = {
4747
INFO: "Run your tests on BrowserStack.",
4848
DESC: "Path to BrowserStack config",
4949
CONFIG_DEMAND: "config file is required"
50+
},
51+
UPDATE_CONFIG: {
52+
INFO: "Updates the browserstack.json with the latest version",
53+
CONFIG_DEMAND_DESC: "Path to BrowserStack config",
54+
CONFIG_DEMAND: "config file is required"
5055
}
5156
}
5257

bin/runner.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ var argv = yargs
3737
return require('./commands/init')(argv);
3838
}
3939
})
40+
.command('update-config', Constants.cliMessages.UPDATE_CONFIG.INFO, function(yargs) {
41+
argv = yargs
42+
.usage('usage: $0 update-config')
43+
.options('cf', {
44+
alias: 'config-file',
45+
describe: Constants.cliMessages.UPDATE_CONFIG.CONFIG_DEMAND_DESC,
46+
default: '/browserstack.json',
47+
type: 'string',
48+
nargs: 1,
49+
demand: true,
50+
demand: Constants.cliMessages.UPDATE_CONFIG.CONFIG_DEMAND
51+
})
52+
.help('help')
53+
.wrap(null)
54+
.argv
55+
56+
if (checkCommands(yargs, argv, 1)) {
57+
return require('./commands/updateConfig')(argv);
58+
}
59+
})
4060
.command('build-info', Constants.cliMessages.BUILD.INFO, function(yargs) {
4161
argv = yargs
4262
.usage('usage: $0 <buildId>')

bin/templates/configTemplate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ module.exports = function () {
1212
}
1313
],
1414
"run_settings": {
15-
"package_json_path": "/path/to/package.json",
1615
"cypress_proj_dir" : "/dir/to/cypress.json",
1716
"project": "project-name",
1817
"customBuildName": "build-name"
1918
},
2019
"connection_settings": {
2120
"local": false,
2221
"localIdentifier": null
22+
},
23+
"cypress_dependencies": {
2324
}
2425
}
2526
var EOL = require('os').EOL

0 commit comments

Comments
 (0)