feature(exit) add ability to receive error as argument

This commit is contained in:
coderaiser 2018-10-12 12:11:15 +03:00
parent 2b9fca8485
commit aacf36babd
3 changed files with 23 additions and 6 deletions

View file

@ -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);
};

View file

@ -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();
});

View file

@ -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';