Skip to content

Commit 391e88a

Browse files
committed
Moved split and join string to function in util and added its specs
1 parent 961eb70 commit 391e88a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

bin/helpers/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ exports.setUserSpecs = (bsConfig, args) => {
102102
let bsConfigSpecs = bsConfig.run_settings.specs;
103103

104104
if (!this.isUndefined(args.specs)) {
105-
bsConfig.run_settings.specs = args.specs.split(/\s{0,},\s+/).join(',');
105+
bsConfig.run_settings.specs = this.fixCommaSeparatedString(args.specs);
106106
} else if (!this.isUndefined(bsConfigSpecs) && Array.isArray(bsConfigSpecs)) {
107107
bsConfig.run_settings.specs = bsConfigSpecs.join(',');
108108
} else if (!this.isUndefined(bsConfigSpecs) && typeof(bsConfigSpecs) == "string") {
109-
bsConfig.run_settings.specs = bsConfigSpecs.split(/\s{0,},\s+/).join(',');
109+
bsConfig.run_settings.specs = this.fixCommaSeparatedString(bsConfigSpecs);
110110
} else {
111111
bsConfig.run_settings.specs = null;
112112
}
@@ -115,12 +115,16 @@ exports.setUserSpecs = (bsConfig, args) => {
115115
// env option must be set only from command line args as a string
116116
exports.setTestEnvs = (bsConfig, args) => {
117117
if (!this.isUndefined(args.env)) {
118-
bsConfig.run_settings.env = args.env.split(/\s{0,},\s+/).join(',');
118+
bsConfig.run_settings.env = this.fixCommaSeparatedString(args.env);
119119
} else {
120120
bsConfig.run_settings.env = null;
121121
}
122122
}
123123

124+
exports.fixCommaSeparatedString = (string) => {
125+
return string.split(/\s{0,},\s+/).join(',');
126+
}
127+
124128
exports.isUndefined = value => (value === undefined || value === null);
125129

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

test/unit/bin/helpers/utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,24 @@ describe("utils", () => {
421421
expect(bsConfig.run_settings.env).to.be.eq(null);
422422
});
423423
});
424+
425+
describe("fixCommaSeparatedString", () => {
426+
it("string with spaces after comma", () => {
427+
let commaString = "string1, string2";
428+
let result = utils.fixCommaSeparatedString(commaString);
429+
expect(result).to.be.eq('string1,string2');
430+
});
431+
432+
it("string with spaces around comma", () => {
433+
let commaString = "string1 , string2";
434+
let result = utils.fixCommaSeparatedString(commaString);
435+
expect(result).to.be.eq('string1,string2');
436+
});
437+
438+
it("string with 2 spaces around comma", () => {
439+
let commaString = "string1 , string2";
440+
let result = utils.fixCommaSeparatedString(commaString);
441+
expect(result).to.be.eq('string1,string2');
442+
});
443+
});
424444
});

0 commit comments

Comments
 (0)