Description
The client tests in this file: https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/client/test/cli/cli.spec.ts look like this:
it('should successfully start client with non-lower case network name', async () => {
const cliArgs = ['--network=Mainnet']
const onData = (message: string, child: ChildProcessWithoutNullStreams, resolve: Function) => {
if (message.includes('Initializing Ethereumjs client')) {
assert.include(
message,
'network=mainnet',
'client is using custom inputs for network and network ID',
)
child.kill()
resolve(undefined)
}
}
await clientRunHelper(cliArgs, onData)
}, 10000)
This, as test itself, is not good for two reasons:
- It listens to the output log and checks if a certain string is included in the message. This thus only checks if a certain log is emitted, not if the client has a certain property or object which we actually expect
- The strings are hardcoded, if we would change a log string in the client then we fail a test which listens to that specific message (it will timeout)
The client needs to be more testable. For this, we'd like that client/bin/cli.ts
exports some method so we can just "start" a client like we would do via command line, but we would like to change the process.argv
string which is input, and we would like this method to return a client object such that we can use that object to inspect certain values.
I got an idea how to change bin/cli.ts
and use that as a starting point to update these tests (and make the client CLI better testable). But anyone who got an idea regarding the text above feel free to move ahead here to update the tests and make the CLI better testable.