mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(exit) add ability to receive error as argument
This commit is contained in:
parent
2b9fca8485
commit
aacf36babd
3 changed files with 23 additions and 6 deletions
|
|
@ -1,7 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (...args) => {
|
||||
console.error(...args);
|
||||
const getMessage = (a) => a && a.message || a;
|
||||
|
||||
module.exports= (...args) => {
|
||||
const messages = args.map(getMessage);
|
||||
|
||||
console.error(...messages);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -32,3 +32,19 @@ test('cloudcmd: exit: console.error', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: exit.error: console.error: error', (t) => {
|
||||
const {exit:exitOriginal} = process;
|
||||
const {error} = console;
|
||||
|
||||
console.error = sinon.stub();
|
||||
process.exit = sinon.stub();
|
||||
|
||||
exit(Error('hello world'));
|
||||
t.ok(console.error.calledWith('hello world'), 'should call console.error');
|
||||
|
||||
process.exit = exitOriginal;
|
||||
console.error = error;
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@ const exitPort = two(exit, 'cloudcmd --port: %s');
|
|||
const bind = (f, self) => f.bind(self);
|
||||
const promisifySelf = squad(promisify, bind);
|
||||
|
||||
const getError = (e) => e.message;
|
||||
const superExit = squad(exitPort, getError);
|
||||
|
||||
const opn = require('opn');
|
||||
const express = require('express');
|
||||
const io = require('socket.io');
|
||||
|
|
@ -54,7 +51,7 @@ module.exports = async (options) => {
|
|||
|
||||
const listen = promisifySelf(server.listen, server);
|
||||
|
||||
server.on('error', superExit);
|
||||
server.on('error', exitPort);
|
||||
await listen(port, ip);
|
||||
|
||||
const host = config('ip') || 'localhost';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue