Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

test: adds test coverage report to @ganache/cli, improve coverage #3735

Open
wants to merge 84 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
fcc4228
feat: allow users to specify a option, which causes Ganache to start…
jeffsmale90 Aug 22, 2022
7a787f2
Stream stderr from the child to the parent
jeffsmale90 Aug 23, 2022
301c500
Tidy up of --detach argument parsing
jeffsmale90 Aug 23, 2022
7dec4c0
Improve detach configuration
jeffsmale90 Aug 24, 2022
9ed54db
Add tests for parsing detach arguments. Change default value to false…
jeffsmale90 Aug 24, 2022
20579ae
Make parent aware of detached instances, and allow stopping them via cli
jeffsmale90 Sep 4, 2022
1da7911
improve args tests, remove placeholder
jeffsmale90 Sep 6, 2022
9cc5b59
Implement , and allow different actions to be executed via the CLI
jeffsmale90 Sep 7, 2022
e5d7e60
Clean up orphaned instance process files. uses a terrible hack to fet…
jeffsmale90 Sep 7, 2022
295b1a3
Implement `instances` command with subcommands. Clean up orphaned ins…
jeffsmale90 Sep 7, 2022
75ffbb0
Tidy up args types and parsing
jeffsmale90 Sep 12, 2022
17732d7
Refactor, add flavor to instance data, and to list output. Change ins…
jeffsmale90 Sep 12, 2022
dea1ddb
Fix createFlatChildArgs import in args.test.ts
jeffsmale90 Sep 20, 2022
07a4b03
Merge branch 'develop' into feat/detach-mode
jeffsmale90 Sep 20, 2022
a74d0a3
Update package-lock.json files - required for new deps
jeffsmale90 Sep 20, 2022
1eaea51
Fix module resolution
jeffsmale90 Sep 20, 2022
cba7589
Tidy ups and refactors
jeffsmale90 Sep 20, 2022
c39cae6
Tidy up arg parsing
jeffsmale90 Sep 20, 2022
bc61cb1
Revert package-lock.json files
jeffsmale90 Sep 20, 2022
f5650f2
Fix miss-typed action name
jeffsmale90 Sep 20, 2022
90a2305
Remove dependency on ps-list, move data files to Ganache/instances, i…
jeffsmale90 Sep 22, 2022
c1e5f43
Remove kebab-case names when expanding arguments. Add tests for expan…
jeffsmale90 Sep 22, 2022
757220b
Reintroduce ps-list, only list instances where the process co
jeffsmale90 Sep 23, 2022
c432c35
Move createFlatChildArgs() to detach.ts, add version to list, ensure …
jeffsmale90 Sep 23, 2022
2dec992
Create instances directory recursively, because now it's
jeffsmale90 Sep 23, 2022
773f21a
Tidy ups from code review, add section on Detached mode to README.
jeffsmale90 Sep 27, 2022
5fb72d1
Fix incorrect command name in README.md
jeffsmale90 Oct 10, 2022
9bf6064
Merge branch 'develop' into feat/detach-mode
jeffsmale90 Oct 10, 2022
d27e6bc
Update to use @trufflesuite/ps-list instead of ps-list
jeffsmale90 Nov 6, 2022
eafc679
If no instances are found, using , print a friendly message instead o…
jeffsmale90 Nov 6, 2022
e6ae996
Revert ganache package version to match develop
jeffsmale90 Nov 6, 2022
eb14694
Merge branch 'develop' into feat/detach-mode
jeffsmale90 Nov 6, 2022
876b972
Bump @trufflesuite/ps-list to include support for node 12
jeffsmale90 Nov 6, 2022
208b149
upgrade @trufflesuite/ps-list to support nodejs < 12.17.0
jeffsmale90 Nov 7, 2022
5f4b80d
Merge branch 'develop' into feat/detach-mode
jeffsmale90 Nov 9, 2022
6b61cba
Improve wording of `--detach` description in README.md
jeffsmale90 Nov 13, 2022
7f36f1f
Switched out for (existing dependency via marked-terminal)
jeffsmale90 Nov 13, 2022
ac5aba0
Move instance list sorting to the consumer that needs the list sorted
jeffsmale90 Nov 15, 2022
bfc5cf9
use detached instance friendly name for instance file (instead of pid)
jeffsmale90 Nov 15, 2022
1a52d4c
pass original process.args to startDetachedInstance, calculate expect…
jeffsmale90 Nov 15, 2022
7a4c256
Fix 'cmd' argument for win32 platform
jeffsmale90 Nov 15, 2022
67d11fc
Add attribution for duration formatter
jeffsmale90 Nov 15, 2022
683c201
Change all detach mode file access to async
jeffsmale90 Nov 15, 2022
60ae164
Adds warning messages if instances removed
jeffsmale90 Nov 15, 2022
1726ec9
Add PID to warning message.
jeffsmale90 Nov 15, 2022
0811874
Remove unnecessary detach.test.ts
jeffsmale90 Nov 15, 2022
485ff64
improvements / refactor as per pr review.
jeffsmale90 Nov 16, 2022
1701140
Don't check for existence of the folder each time - just catch the Er…
jeffsmale90 Nov 16, 2022
78a9d0c
Accidentally recreated the instance name twice
jeffsmale90 Nov 16, 2022
04719a6
Move comment to relevant code
jeffsmale90 Nov 16, 2022
3ea9968
Improvements to detach re PR
jeffsmale90 Nov 16, 2022
6a7f3b3
Revert package-lock.json
jeffsmale90 Nov 16, 2022
c5c0c31
_Actually_ fix package-lock.json this time
jeffsmale90 Nov 16, 2022
bc8d269
Remove nyc dev-dependency from cli/package.json - correct, but irrele…
jeffsmale90 Nov 16, 2022
aa72840
Strip the detach argument correctly before passing arguments to child…
jeffsmale90 Nov 16, 2022
4e8f933
Add tests for duration formatting - move implementation into detach.ts
jeffsmale90 Nov 18, 2022
6b49cbb
Rename formatDuration to formatUptime, add --detach example to README…
jeffsmale90 Nov 18, 2022
0435951
Revert shrinkwrap :/
jeffsmale90 Nov 18, 2022
959c6dc
Pin cli-table dependency to latest release
jeffsmale90 Nov 18, 2022
dfb8b72
Fix failing test
jeffsmale90 Nov 18, 2022
c495cc9
Improve duration formatting, improve readme
jeffsmale90 Nov 22, 2022
c16cb20
Annoyingly, args parsing is complicated. Don't try to strip out the d…
jeffsmale90 Nov 22, 2022
b272237
Instance files now have .json extension. Remove any files / folders f…
jeffsmale90 Nov 22, 2022
c85d022
Remove unused import
jeffsmale90 Nov 22, 2022
359cb6b
Handle errors betterer
jeffsmale90 Nov 23, 2022
f94442f
Shorten duration formatting, combine host and port, right align PID i…
jeffsmale90 Nov 23, 2022
26af55e
RH align Uptime
jeffsmale90 Nov 23, 2022
d717d3f
remove unnecessary type assertion, remove datapath suffix
jeffsmale90 Nov 23, 2022
393702c
Use unlink instead of rm, because node 12
jeffsmale90 Nov 25, 2022
0507aa4
Support ndoe 12 correctly for removal of files and directories
jeffsmale90 Nov 28, 2022
d09c3d5
Add test coverage, improve test coverage of process-name, and args
jeffsmale90 Sep 28, 2022
fba36c8
Add integration tests for detach mode - actually starting ganache det…
jeffsmale90 Nov 24, 2022
eea355b
Increase timeout in startDetachedInstance test, and fix regex test in…
jeffsmale90 Nov 25, 2022
f62d0bf
Add more tests to cover detach mode
jeffsmale90 Nov 29, 2022
4d098ff
Add explicit test case for the detached ganache instance not starting
jeffsmale90 Nov 29, 2022
3a147c3
Update package-lock.json
jeffsmale90 Nov 29, 2022
f11f58f
Fix failing test
jeffsmale90 Nov 29, 2022
d364fab
Fix import so that node 12
jeffsmale90 Nov 29, 2022
29e6959
Increase timeout because slow tests
jeffsmale90 Nov 29, 2022
dcdcb91
Merge branch 'develop' into test/improve_cli_tests
jeffsmale90 Dec 19, 2022
6571c79
Ensure that dataPath is created recursively, fix fx/promises import
jeffsmale90 Dec 21, 2022
1dc6029
Remove duplicate dependency declarations from package.json
jeffsmale90 Dec 21, 2022
4e84063
Merge develop
jeffsmale90 Jan 4, 2023
ac57953
Revert change to package.json
jeffsmale90 Jan 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,358 changes: 1,349 additions & 9 deletions src/packages/cli/package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"scripts": {
"tsc": "tsc --build",
"test": "nyc npm run mocha",
"test": "nyc --reporter lcov npm run mocha",
"mocha": "cross-env TS_NODE_FILES=true mocha --exit --check-leaks --throw-deprecation --trace-warnings --require ts-node/register 'tests/**/*.test.ts'",
"start": "cross-env node --require ts-node/register --inspect src/cli.ts"
},
Expand Down Expand Up @@ -59,7 +59,9 @@
"cross-env": "7.0.3",
"mocha": "9.1.3",
"ts-node": "10.9.1",
"typescript": "4.7.4"
"typescript": "4.7.4",
"superagent": "6.1.0",
"nyc": "15.1.0"
},
"dependencies": {
"@ethereumjs/util": "8.0.2",
Expand Down
50 changes: 33 additions & 17 deletions src/packages/cli/src/args.ts
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,
Expand All @@ -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";

Expand All @@ -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);
};
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default Yargs terminates the process if --help provided, or if validation fails.

With this change, we will pass through if --help is provided (and return { action: "help }), and throw if validation fails.

This allows us to test args validation more thoroughly, and we handle the thrown error in cli.ts

.strict()
.usage(versionUsageOutputText)
.epilogue(
Expand All @@ -188,12 +194,9 @@ export default function (
command = ["$0", flavor];
defaultPort = 8545;
break;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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 => {
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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");
}
Expand All @@ -244,7 +252,7 @@ export default function (
);
}

yargs
yargsParser
.command(
"instances",
highlight(
Expand Down Expand Up @@ -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);
}
)
Expand All @@ -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") {
Expand Down Expand Up @@ -308,7 +324,7 @@ export default function (
>)
};
} else {
throw new Error(`Unknown action: ${parsedArgs.action}`);
finalArgs = { action: "none" };
}

return finalArgs;
Expand Down
Loading