Skip to content

Commit b582a14

Browse files
committed
improve coverage
1 parent f8477dc commit b582a14

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

bin/commands/init.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@ module.exports = function init(args) {
1616
path: path_to_bsconf
1717
};
1818

19-
function allDone() {
20-
let message = Constants.userMessages.CONFIG_FILE_CREATED
21-
logger.info(message);
22-
utils.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
23-
}
24-
2519
return fileHelpers.fileExists(config.path, function(exists){
2620
if (exists) {
2721
let message = Constants.userMessages.CONFIG_FILE_EXISTS;
2822
logger.error(message);
2923
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
3024
} else {
31-
fileHelpers.write(config, null, allDone);
25+
fileHelpers.write(config, null, utils.configCreated(args));
3226
}
3327
});
3428
}

bin/helpers/fileHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const logger = require("./logger").winstonLogger,
99
exports.write = function(f, message, cb) {
1010
message = message || 'Creating';
1111
fs.writeFile(f.path, f.file, function() {
12-
logger.info(message + " file: ./" + path.relative(process.cwd(), f.path));
12+
logger.info(message + " file: " + path.relative(process.cwd(), f.path));
1313
cb && cb()
1414
});
1515
}

bin/helpers/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ exports.isAbsolute = (configPath) => {
114114
exports.getConfigPath = (configPath) => {
115115
return this.isAbsolute(configPath) ? configPath : path.join(process.cwd(), configPath);
116116
}
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+
}

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
before(() => {
1919
sandbox = sinon.createSandbox();
20+
configCreatedStub = sandbox.stub()
2021
sendUsageReportStub = sandbox.stub().callsFake(function () {
2122
return "end";
2223
});
@@ -55,6 +56,7 @@ describe("init", () => {
5556
const init = proxyquire("../../../../bin/commands/init", {
5657
"../helpers/utils": {
5758
sendUsageReport: sendUsageReportStub,
59+
configCreated: configCreatedStub
5860
},
5961
"../helpers/fileHelpers": {
6062
fileExists: fileExistsStub,

test/unit/bin/helpers/utils.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ const path = require('path');
33

44
const chai = require("chai"),
55
expect = chai.expect,
6+
sinon = require('sinon'),
67
chaiAsPromised = require("chai-as-promised");
78

89
const utils = require('../../../../bin/helpers/utils'),
910
constant = require('../../../../bin/helpers/constants'),
10-
logger = require('../../../../bin/helpers/logger').winstonLogger;
11+
logger = require('../../../../bin/helpers/logger').winstonLogger,
12+
testObjects = require("../../support/fixtures/testObjects");
1113

1214
chai.use(chaiAsPromised);
1315
logger.transports["console.info"].silent = true;
@@ -35,7 +37,7 @@ describe("utils", () => {
3537
expect(utils.isParallelValid("1.2.2.2")).to.be.equal(false);
3638
expect(utils.isParallelValid("1.456789")).to.be.equal(false);
3739
});
38-
40+
3941
it("should return false for a string which is not a number", () => {
4042
expect(utils.isParallelValid("cypress")).to.be.equal(false);
4143
expect(utils.isParallelValid("browserstack")).to.be.equal(false);
@@ -220,6 +222,18 @@ describe("utils", () => {
220222
let configPath = "../Relative/Path"
221223
expect(utils.getConfigPath(configPath)).to.be.eq(path.join(process.cwd(), configPath));
222224
});
225+
});
223226

227+
describe("configCreated", () => {
228+
let args = testObjects.initSampleArgs;
229+
230+
it("should call sendUsageReport", () => {
231+
sandbox = sinon.createSandbox();
232+
sendUsageReportStub = sandbox.stub(utils, "sendUsageReport").callsFake(function () {
233+
return "end";
234+
});
235+
utils.configCreated(args);
236+
sinon.assert.calledOnce(sendUsageReportStub);
237+
});
224238
});
225239
});

0 commit comments

Comments
 (0)