Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit b1d65f0

Browse files
committed
Add CommandLineArguments unit tests
1 parent 496c68f commit b1d65f0

4 files changed

Lines changed: 439 additions & 15 deletions

File tree

jest.config.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ module.exports = {
1717
// An object that configures minimum threshold enforcement for coverage results
1818
coverageThreshold: {
1919
global: {
20-
branches: 60,
21-
functions: 70,
22-
lines: 70,
23-
statements: 70
20+
branches: 70,
21+
functions: 75,
22+
lines: 75,
23+
statements: 75
2424
}
2525
},
2626

@@ -42,9 +42,10 @@ module.exports = {
4242
"**/test/unit/core/mocks/Behaviors.spec.js",
4343
"**/test/unit/core/mocks/FilesHandler.spec.js",
4444
"**/test/unit/core/mocks/Mocks.spec.js",
45-
"**/test/unit/core/server/Server.spec.js"
45+
"**/test/unit/core/server/Server.spec.js",
46+
"**/test/unit/core/settings/CommandLineArguments.spec.js"
4647
],
47-
//testMatch: ["**/test/unit/core/server/Server.spec.js"],
48+
//testMatch: ["**/test/unit/core/settings/CommandLineArguments.spec.js"],
4849

4950
// The test environment that will be used for testing
5051
testEnvironment: "node"

lib/core/settings/CommandLineArguments.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CommandLineArguments {
2626
.option("--host <host>", "Host for server")
2727
.option("--log <log>", "Log level")
2828
.option("--port <port>", "Port for server", parseInt)
29-
.option("--watch", "Watch or not", this._stringToBoolean)
29+
.option("--watch <watch>", "Watch or not", this._stringToBoolean) // TODO, change by --no-watch option
3030
// TODO, remove deprecated options
3131
.option("--feature <feature>", "Define current behavior")
3232
.option("--features <features>", "Define folder from which load behaviors");
@@ -40,10 +40,11 @@ class CommandLineArguments {
4040
return Promise.resolve();
4141
}
4242

43+
// TODO, deprecate "stringBoolean" options. Use --no- commander feature
4344
_stringToBoolean(val) {
44-
if (val === "true") {
45+
if (isUndefined(val) || val === "true") {
4546
return true;
46-
} else if (isUndefined(val) || val === "false") {
47+
} else if (val === "false") {
4748
return false;
4849
}
4950
throw new Error("Invalid boolean value");
@@ -59,19 +60,16 @@ class CommandLineArguments {
5960
}
6061

6162
addCustom(optionDetails) {
62-
const optionValueGetter =
63-
optionDetails.type === "string" || optionDetails.type === "booleanString"
64-
? ` <${optionDetails.name}>`
65-
: "";
63+
const optionPrefix =
64+
optionDetails.type === "boolean" && optionDetails.default === true ? "--no-" : "--";
65+
const optionValueGetter = optionDetails.type === "boolean" ? "" : ` <${optionDetails.name}>`;
6666
const optionParser = optionDetails.parse
6767
? optionDetails.parse
6868
: optionDetails.type === "number"
6969
? parseInt
7070
: optionDetails.type === "booleanString"
7171
? this._stringToBoolean
7272
: undefined;
73-
const optionPrefix =
74-
optionDetails.type === "boolean" && optionDetails.default === true ? "--no-" : "--";
7573

7674
this._commander.option(
7775
`${optionPrefix}${optionDetails.name}${optionValueGetter}`,

test/acceptance/main/InteractiveCliRunner.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
Copyright 2019 Javier Brea
3+
4+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
9+
*/
10+
111
const { CliRunner, wait } = require("./utils");
212

313
const LOG = "[CLI]: ";

0 commit comments

Comments
 (0)