This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client config file and custom logger support
- Loading branch information
Showing
3 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import path from 'path' | ||
import { spawn } from 'child_process' | ||
|
||
import tape from 'tape' | ||
|
||
tape('[CLI]', (t) => { | ||
t.test('should handle SIGINT', { timeout: 160000 }, (t) => { | ||
t.plan(1) | ||
const file = require.resolve('../../dist/bin/cli.js') | ||
const child = spawn(process.execPath, [ | ||
file, | ||
'--config', | ||
path.join(__dirname, '/fixtures/ethereumjs.config.js') | ||
], { | ||
stdio: ['pipe', 'pipe', 'pipe', 'ipc'], | ||
}) | ||
|
||
const timeout = setTimeout(() => { | ||
child.kill('SIGINT') | ||
}, 120000) | ||
|
||
const end = () => { | ||
clearTimeout(timeout) | ||
child.kill('SIGINT') | ||
t.end() | ||
} | ||
|
||
function onServiceStarted([level, message]: [string, string]) { | ||
if (level === 'info') { | ||
if (message === 'Started eth service.') { | ||
child.removeListener('message', onServiceStarted) | ||
child.on('message', onFirstSigintSent) | ||
child.kill('SIGINT') | ||
} | ||
} | ||
} | ||
|
||
function onFirstSigintSent([level, message]: [string, string]) { | ||
if (level === 'info') { | ||
if (message === 'Exiting.') { | ||
child.removeListener('message', onFirstSigintSent) | ||
t.pass('Client exited') | ||
clearTimeout(timeout) | ||
} | ||
} | ||
} | ||
|
||
child.on('message', onServiceStarted) | ||
child.on('message', ([level, message]: [string, string]) => console.log(level, message)) | ||
|
||
child.on('error', (error) => { | ||
t.fail(`Error: ${error}`) | ||
}) | ||
|
||
child.on('close', (code, signal) => { | ||
if (code !== 0) { | ||
t.fail(`child process exited with code ${code}, signal ${signal}`) | ||
end() | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function send(level, message) { | ||
process.send([level, message]) | ||
} | ||
|
||
module.exports = { | ||
logger: { | ||
warn: send.bind(null, 'warn'), | ||
info: send.bind(null, 'info'), | ||
debug: send.bind(null, 'debug'), | ||
error: send.bind(null, 'error'), | ||
} | ||
} |