This repository was archived by the owner on Oct 30, 2018. It is now read-only.
File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -222,4 +222,44 @@ describe('module:utils', function() {
222
222
223
223
} ) ;
224
224
225
+ describe ( '#connectToDaemon' , function ( ) {
226
+
227
+ it ( 'should set the process exit code and log error' , function ( done ) {
228
+ let socket = new EventEmitter ( ) ;
229
+ let error = sinon . stub ( console , 'error' ) ;
230
+ let _utils = proxyquire ( '../lib/utils' , {
231
+ dnode : {
232
+ connect : ( ) => socket
233
+ }
234
+ } ) ;
235
+ _utils . connectToDaemon ( 45015 , ( ) => null ) ;
236
+ setImmediate ( ( ) => {
237
+ socket . emit ( 'error' , new Error ( 'Failed to connect' ) ) ;
238
+ setImmediate ( ( ) => {
239
+ error . restore ( ) ;
240
+ expect ( process . exitCode ) . to . equal ( 1 ) ;
241
+ process . exitCode = 0 ;
242
+ done ( ) ;
243
+ } ) ;
244
+ } ) ;
245
+ } ) ;
246
+
247
+ it ( 'should callback with remote object and socket' , function ( done ) {
248
+ let socket = new EventEmitter ( ) ;
249
+ let rpc = { } ;
250
+ let _utils = proxyquire ( '../lib/utils' , {
251
+ dnode : {
252
+ connect : ( ) => socket
253
+ }
254
+ } ) ;
255
+ _utils . connectToDaemon ( 45015 , ( _rpc , sock ) => {
256
+ expect ( _rpc ) . to . equal ( rpc ) ;
257
+ expect ( sock ) . to . equal ( socket ) ;
258
+ done ( ) ;
259
+ } ) ;
260
+ setImmediate ( ( ) => socket . emit ( 'remote' , rpc ) ) ;
261
+ } ) ;
262
+
263
+ } ) ;
264
+
225
265
} ) ;
You can’t perform that action at this time.
0 commit comments