Skip to content

Commit 8cf8177

Browse files
committed
Merge branch 'CYP_277_handle_absolute_config_path' of https://github.com/browserstack/browserstack-cypress-cli into CYP_9999_fix_logging_in_init
2 parents 9ae96e2 + e0bcd19 commit 8cf8177

File tree

14 files changed

+128
-29
lines changed

14 files changed

+128
-29
lines changed

bin/commands/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const config = require("../helpers/config"),
77
utils = require("../helpers/utils");
88

99
module.exports = function info(args) {
10-
let bsConfigPath = process.cwd() + args.cf;
10+
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
1313
// accept the username from command line if provided

bin/commands/init.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ module.exports = function init(args) {
1818
path: path_to_bsconf
1919
};
2020

21-
function allDone() {
22-
let message = Constants.userMessages.CONFIG_FILE_CREATED
23-
logger.info(message);
24-
utils.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
25-
}
26-
2721
return fileHelpers.dirExists(config.path, function(dirExists){
2822
if (dirExists) {
2923
fileHelpers.fileExists(config.path, function(exists){
@@ -32,7 +26,7 @@ module.exports = function init(args) {
3226
logger.error(message);
3327
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
3428
} else {
35-
fileHelpers.write(config, null, allDone);
29+
fileHelpers.write(config, null, args, utils.configCreated);
3630
}
3731
});
3832
} else {

bin/commands/runs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const archiver = require("../helpers/archiver"),
1010
fileHelpers = require("../helpers/fileHelpers");
1111

1212
module.exports = function run(args) {
13-
let bsConfigPath = process.cwd() + args.cf;
13+
let bsConfigPath = utils.getConfigPath(args.cf);
1414

1515
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
1616
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);

bin/commands/stop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const config = require("../helpers/config"),
77
utils = require("../helpers/utils");
88

99
module.exports = function stop(args) {
10-
let bsConfigPath = process.cwd() + args.cf;
10+
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
1313
// accept the username from command line if provided

bin/helpers/fileHelpers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const logger = require("./logger").winstonLogger,
66
Constants = require("../helpers/constants"),
77
config = require("../helpers/config");
88

9-
exports.write = function(f, message, cb) {
9+
exports.write = function(f, message, args, cb) {
1010
message = message || 'Creating';
1111
fs.writeFile(f.path, f.file, function() {
12-
logger.info(message + " file: ./" + path.relative(process.cwd(), f.path));
13-
cb && cb()
12+
logger.info(message + " file: " + f.path);
13+
cb && cb(args)
1414
});
1515
}
1616

bin/helpers/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const os = require("os");
3+
const path = require("path");
34

45
const usageReporting = require('./usageReporting'),
56
logger = require('./logger').winstonLogger,
@@ -105,3 +106,17 @@ exports.isParallelValid = (value) => {
105106
exports.getUserAgent = () => {
106107
return `BStack-Cypress-CLI/1.2.0 (${os.arch()}/${os.platform()}/${os.release()})`;
107108
}
109+
110+
exports.isAbsolute = (configPath) => {
111+
return path.isAbsolute(configPath)
112+
}
113+
114+
exports.getConfigPath = (configPath) => {
115+
return this.isAbsolute(configPath) ? configPath : path.join(process.cwd(), configPath);
116+
}
117+
118+
exports.configCreated = (args) => {
119+
let message = Constants.userMessages.CONFIG_FILE_CREATED
120+
logger.info(message);
121+
this.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
122+
}

bin/runner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var argv = yargs
5151
'cf': {
5252
alias: 'config-file',
5353
describe: Constants.cliMessages.BUILD.DESC,
54-
default: '/browserstack.json',
54+
default: 'browserstack.json',
5555
type: 'string',
5656
nargs: 1,
5757
demand: true,
@@ -91,7 +91,7 @@ var argv = yargs
9191
'cf': {
9292
alias: 'config-file',
9393
describe: Constants.cliMessages.BUILD.DESC,
94-
default: '/browserstack.json',
94+
default: 'browserstack.json',
9595
type: 'string',
9696
nargs: 1,
9797
demand: true,
@@ -130,7 +130,7 @@ var argv = yargs
130130
'cf': {
131131
alias: 'config-file',
132132
describe: Constants.cliMessages.RUN.DESC,
133-
default: '/browserstack.json',
133+
default: 'browserstack.json',
134134
type: 'string',
135135
nargs: 1,
136136
demand: true,

test/unit/bin/commands/info.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe("buildInfo", () => {
2525
setUsernameStub = sandbox.stub();
2626
setAccessKeyStub = sandbox.stub();
2727
validateBstackJsonStub = sandbox.stub();
28+
getConfigPathStub = sandbox.stub();
2829
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
2930
getUserAgentStub = sandbox.stub().returns("random user-agent");
3031
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -54,6 +55,7 @@ describe("buildInfo", () => {
5455
sendUsageReport: sendUsageReportStub,
5556
setUsageReportingFlag: setUsageReportingFlagStub,
5657
getUserAgent: getUserAgentStub,
58+
getConfigPath: getConfigPathStub
5759
},
5860
request: { get: requestStub },
5961
});
@@ -63,6 +65,7 @@ describe("buildInfo", () => {
6365
return info(args)
6466
.then(function (_bsConfig) {
6567
sinon.assert.calledOnce(requestStub);
68+
sinon.assert.calledOnce(getConfigPathStub);
6669
sinon.assert.calledOnce(getUserAgentStub);
6770
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
6871
}).catch((error) => {
@@ -88,6 +91,7 @@ describe("buildInfo", () => {
8891
sendUsageReport: sendUsageReportStub,
8992
setUsageReportingFlag: setUsageReportingFlagStub,
9093
getUserAgent: getUserAgentStub,
94+
getConfigPath: getConfigPathStub
9195
},
9296
request: { get: requestStub },
9397
});
@@ -98,6 +102,7 @@ describe("buildInfo", () => {
98102
.then(function (_bsConfig) {
99103
sinon.assert.calledOnce(requestStub);
100104
sinon.assert.calledOnce(getUserAgentStub);
105+
sinon.assert.calledOnce(getConfigPathStub);
101106
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
102107
})
103108
.catch((error) => {
@@ -112,6 +117,7 @@ describe("buildInfo", () => {
112117
setUsernameStub = sandbox.stub();
113118
setAccessKeyStub = sandbox.stub();
114119
validateBstackJsonStub = sandbox.stub();
120+
getConfigPathStub = sandbox.stub();
115121
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
116122
getUserAgentStub = sandbox.stub().returns("random user-agent");
117123
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -143,6 +149,7 @@ describe("buildInfo", () => {
143149
sendUsageReport: sendUsageReportStub,
144150
setUsageReportingFlag: setUsageReportingFlagStub,
145151
getUserAgent: getUserAgentStub,
152+
getConfigPath: getConfigPathStub
146153
},
147154
request: { get: requestStub },
148155
});
@@ -153,6 +160,7 @@ describe("buildInfo", () => {
153160
.then(function (_bsConfig) {
154161
sinon.assert.calledOnce(requestStub);
155162
sinon.assert.calledOnce(getUserAgentStub);
163+
sinon.assert.calledOnce(getConfigPathStub);
156164
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
157165
})
158166
.catch((error) => {
@@ -183,6 +191,7 @@ describe("buildInfo", () => {
183191
sendUsageReport: sendUsageReportStub,
184192
setUsageReportingFlag: setUsageReportingFlagStub,
185193
getUserAgent: getUserAgentStub,
194+
getConfigPath: getConfigPathStub
186195
},
187196
request: { get: requestStub },
188197
});
@@ -193,6 +202,7 @@ describe("buildInfo", () => {
193202
.then(function (_bsConfig) {
194203
sinon.assert.calledOnce(requestStub);
195204
sinon.assert.calledOnce(getUserAgentStub);
205+
sinon.assert.calledOnce(getConfigPathStub);
196206
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
197207
})
198208
.catch((error) => {
@@ -218,6 +228,7 @@ describe("buildInfo", () => {
218228
sendUsageReport: sendUsageReportStub,
219229
setUsageReportingFlag: setUsageReportingFlagStub,
220230
getUserAgent: getUserAgentStub,
231+
getConfigPath: getConfigPathStub
221232
},
222233
request: { get: requestStub },
223234
});
@@ -228,6 +239,7 @@ describe("buildInfo", () => {
228239
.then(function (_bsConfig) {
229240
sinon.assert.calledOnce(requestStub);
230241
sinon.assert.calledOnce(getUserAgentStub);
242+
sinon.assert.calledOnce(getConfigPathStub);
231243
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
232244
})
233245
.catch((error) => {
@@ -244,6 +256,7 @@ describe("buildInfo", () => {
244256
setUsernameStub = sandbox.stub();
245257
setAccessKeyStub = sandbox.stub();
246258
validateBstackJsonStub = sandbox.stub();
259+
getConfigPathStub = sandbox.stub();
247260
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
248261
getUserAgentStub = sandbox.stub().returns("random user-agent");
249262
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -273,6 +286,7 @@ describe("buildInfo", () => {
273286
sendUsageReport: sendUsageReportStub,
274287
setUsageReportingFlag: setUsageReportingFlagStub,
275288
getUserAgent: getUserAgentStub,
289+
getConfigPath: getConfigPathStub
276290
},
277291
request: { get: requestStub },
278292
});
@@ -283,6 +297,7 @@ describe("buildInfo", () => {
283297
.then(function (_bsConfig) {
284298
sinon.assert.calledOnce(requestStub);
285299
sinon.assert.calledOnce(getUserAgentStub);
300+
sinon.assert.calledOnce(getConfigPathStub);
286301
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
287302
}).catch((error) => {
288303
chai.assert.isNotOk(error,'Promise error');
@@ -297,6 +312,7 @@ describe("buildInfo", () => {
297312
sandbox = sinon.createSandbox();
298313
setUsernameStub = sandbox.stub();
299314
setAccessKeyStub = sandbox.stub();
315+
getConfigPathStub = sandbox.stub();
300316
validateBstackJsonStub = sandbox.stub();
301317
setUsageReportingFlagStub = sandbox.stub().returns(undefined);
302318
sendUsageReportStub = sandbox.stub().callsFake(function () {
@@ -319,6 +335,7 @@ describe("buildInfo", () => {
319335
getErrorCodeFromErr: getErrorCodeFromErrStub,
320336
sendUsageReport: sendUsageReportStub,
321337
setUsageReportingFlag: setUsageReportingFlagStub,
338+
getConfigPath: getConfigPathStub
322339
},
323340
});
324341

test/unit/bin/commands/init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe("init", () => {
1717

1818
beforeEach(() => {
1919
sandbox = sinon.createSandbox();
20+
configCreatedStub = sandbox.stub()
2021
sendUsageReportStub = sandbox.stub().callsFake(function () {
2122
return "end";
2223
});
@@ -79,6 +80,7 @@ describe("init", () => {
7980
const init = proxyquire("../../../../bin/commands/init", {
8081
"../helpers/utils": {
8182
sendUsageReport: sendUsageReportStub,
83+
configCreated: configCreatedStub
8284
},
8385
"../helpers/fileHelpers": {
8486
dirExists: dirExistsStub,

0 commit comments

Comments
 (0)