-
Notifications
You must be signed in to change notification settings - Fork 681
test: adds test coverage report to @ganache/cli, improve coverage #3735
base: develop
Are you sure you want to change the base?
Changes from 83 commits
fcc4228
7a787f2
301c500
7dec4c0
9ed54db
20579ae
1da7911
9cc5b59
e5d7e60
295b1a3
75ffbb0
17732d7
dea1ddb
07a4b03
a74d0a3
1eaea51
cba7589
c39cae6
bc61cb1
f5650f2
90a2305
c1e5f43
757220b
c432c35
2dec992
773f21a
5fb72d1
9bf6064
d27e6bc
eafc679
e6ae996
eb14694
876b972
208b149
5f4b80d
6b61cba
7f36f1f
ac5aba0
bfc5cf9
1a52d4c
7a4c256
67d11fc
683c201
60ae164
1726ec9
0811874
485ff64
1701140
78a9d0c
04719a6
3ea9968
6a7f3b3
c5c0c31
bc8d269
aa72840
4e8f933
6b49cbb
0435951
959c6dc
dfb8b72
c495cc9
c16cb20
b272237
c85d022
359cb6b
f94442f
26af55e
d717d3f
393702c
0507aa4
d09c3d5
fba36c8
eea355b
f62d0bf
4d098ff
3a147c3
f11f58f
d364fab
29e6959
dcdcb91
6571c79
1dc6029
4e84063
ac57953
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
// `import Yargs from "yargs"` is the Yargs singleton and namespace | ||
// `import yargs from "yargs/yargs"` is the non-singleton interface | ||
// See https://github.com/yargs/yargs/issues/1648 | ||
import Yargs, { Options } from "yargs"; | ||
import yargs from "yargs/yargs"; | ||
|
||
import { TruffleColors } from "@ganache/colors"; | ||
import yargs, { Options } from "yargs"; | ||
import { | ||
DefaultFlavor, | ||
FilecoinFlavorName, | ||
|
@@ -26,7 +31,7 @@ marked.setOptions({ | |
}) | ||
}); | ||
|
||
const wrapWidth = Math.min(120, yargs.terminalWidth()); | ||
const wrapWidth = Math.min(120, Yargs.terminalWidth()); | ||
const NEED_HELP = "Need more help? Reach out to the Truffle community at"; | ||
const COMMUNITY_LINK = "https://trfl.io/support"; | ||
|
||
|
@@ -43,7 +48,7 @@ const highlight = (t: string) => unescapeEntities(marked.parseInline(t)); | |
const center = (str: string) => | ||
" ".repeat(Math.max(0, Math.floor((wrapWidth - str.length) / 2))) + str; | ||
|
||
const addAliases = (args: yargs.Argv<{}>, aliases: string[], key: string) => { | ||
const addAliases = (args: Yargs.Argv<{}>, aliases: string[], key: string) => { | ||
const options = { hidden: true, alias: key }; | ||
return aliases.reduce((args, a) => args.option(a, options), args); | ||
}; | ||
|
@@ -54,7 +59,7 @@ function processOption( | |
group: string, | ||
option: string, | ||
optionObj: Definitions<Base.Config>[string], | ||
argv: yargs.Argv, | ||
argv: Yargs.Argv, | ||
flavor: string | ||
) { | ||
if (optionObj.disableInCLI !== true) { | ||
|
@@ -122,7 +127,7 @@ function applyDefaults( | |
flavorDefaults: | ||
| typeof DefaultOptionsByName[keyof typeof DefaultOptionsByName] | ||
| typeof _DefaultServerOptions, | ||
flavorArgs: yargs.Argv<{}>, | ||
flavorArgs: Yargs.Argv<{}>, | ||
flavor: keyof typeof DefaultOptionsByName | ||
) { | ||
for (const category in flavorDefaults) { | ||
|
@@ -160,8 +165,9 @@ export default function ( | |
|
||
// disable dot-notation because yargs just can't coerce args properly... | ||
// ...on purpose! https://github.com/yargs/yargs/issues/1021#issuecomment-352324693 | ||
yargs | ||
const yargsParser = yargs() | ||
davidmurdoch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.parserConfiguration({ "dot-notation": false }) | ||
.exitProcess(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By default Yargs terminates the process if With this change, we will pass through if This allows us to test args validation more thoroughly, and we handle the thrown error in cli.ts |
||
.strict() | ||
.usage(versionUsageOutputText) | ||
.epilogue( | ||
|
@@ -188,12 +194,9 @@ export default function ( | |
command = ["$0", flavor]; | ||
defaultPort = 8545; | ||
break; | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, this code path is unreachable, as the only valid flavors are "ethereum" and "filecoin", which are handled above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all being removed in another PR. This change will just add to the painful merge conflicts to come. |
||
command = flavor; | ||
defaultPort = 8545; | ||
} | ||
|
||
yargs.command( | ||
yargsParser.command( | ||
command, | ||
chalk`Use the {bold ${flavor}} flavor of Ganache`, | ||
flavorArgs => { | ||
|
@@ -214,14 +217,19 @@ export default function ( | |
description: chalk`Port to listen on.${EOL}{dim deprecated aliases: --port}${EOL}`, | ||
alias: ["p", "port"], | ||
type: "number", | ||
default: defaultPort | ||
default: defaultPort, | ||
// `string: true` to allow raw value to be used in validation below | ||
// (otherwise string values becomes NaN) | ||
string: true, | ||
coerce: port => (isFinite(port) ? +port : port) | ||
}) | ||
.check(argv => { | ||
const { "server.port": port, "server.host": host } = argv; | ||
if (port < 1 || port > 65535) { | ||
throw new Error(`Invalid port number '${port}'`); | ||
if (!isFinite(port) || port < 1 || port > 65535) { | ||
throw new Error( | ||
`Port should be >= 0 and < 65536. Received ${port}.` | ||
); | ||
Comment on lines
+228
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will conflict with #4070 |
||
} | ||
|
||
if (host.trim() === "") { | ||
throw new Error("Cannot leave host blank; please provide a host"); | ||
} | ||
|
@@ -244,7 +252,7 @@ export default function ( | |
); | ||
} | ||
|
||
yargs | ||
yargsParser | ||
.command( | ||
"instances", | ||
highlight( | ||
|
@@ -272,6 +280,14 @@ export default function ( | |
stopArgs.action = "stop"; | ||
} | ||
) | ||
.check(instancesArgs => { | ||
if (instancesArgs["_"].length <= 1) { | ||
throw new Error( | ||
"No sub-command given. See `ganache instances --help` for more information." | ||
); | ||
} | ||
return true; | ||
}) | ||
.version(false); | ||
} | ||
) | ||
|
@@ -280,7 +296,7 @@ export default function ( | |
.wrap(wrapWidth) | ||
.version(version); | ||
|
||
const parsedArgs = yargs.parse(rawArgs); | ||
const parsedArgs = yargsParser.parse(rawArgs); | ||
|
||
let finalArgs: GanacheArgs; | ||
if (parsedArgs.action === "stop") { | ||
|
@@ -308,7 +324,7 @@ export default function ( | |
>) | ||
}; | ||
} else { | ||
throw new Error(`Unknown action: ${parsedArgs.action}`); | ||
finalArgs = { action: "none" }; | ||
} | ||
|
||
return finalArgs; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change on purpose? It seems like the versions are the same and they are now out of alphabetical order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope!