@@ -104,14 +104,13 @@ describe('daemon', () => {
104104 }
105105 } )
106106
107- try {
108- await daemon
109- throw new Error ( 'Did not kill process' )
110- } catch ( err ) {
111- expect ( err . killed ) . to . be . true ( )
112-
113- expect ( stdout ) . to . include ( 'Daemon is ready' )
114- }
107+ await daemon . then (
108+ ( ) => expect . fail ( 'Did not kill process' ) ,
109+ ( err ) => {
110+ expect ( err . killed ) . to . be . true ( )
111+ expect ( stdout ) . to . include ( 'Daemon is ready' )
112+ }
113+ )
115114 } )
116115
117116 it ( 'should allow bind to multiple addresses for API and Gateway' , async function ( ) {
@@ -142,15 +141,15 @@ describe('daemon', () => {
142141 }
143142 } )
144143
145- try {
146- await daemon
147- throw new Error ( 'Did not kill process' )
148- } catch ( err ) {
149- expect ( err . killed ) . to . be . true ( )
144+ await daemon . then (
145+ ( ) => expect . fail ( 'Did not kill process' ) ,
146+ ( err ) => {
147+ expect ( err . killed ) . to . be . true ( )
150148
151- apiAddrs . forEach ( addr => expect ( err . stdout ) . to . include ( `API listening on ${ addr . slice ( 0 , - 2 ) } ` ) )
152- gatewayAddrs . forEach ( addr => expect ( err . stdout ) . to . include ( `Gateway (read only) listening on ${ addr . slice ( 0 , - 2 ) } ` ) )
153- }
149+ apiAddrs . forEach ( addr => expect ( err . stdout ) . to . include ( `API listening on ${ addr . slice ( 0 , - 2 ) } ` ) )
150+ gatewayAddrs . forEach ( addr => expect ( err . stdout ) . to . include ( `Gateway (read only) listening on ${ addr . slice ( 0 , - 2 ) } ` ) )
151+ }
152+ )
154153 } )
155154
156155 it ( 'should allow no bind addresses for API and Gateway' , async function ( ) {
@@ -171,15 +170,15 @@ describe('daemon', () => {
171170 }
172171 } )
173172
174- try {
175- await daemon
176- throw new Error ( 'Did not kill process' )
177- } catch ( err ) {
178- expect ( err . killed ) . to . be . true ( )
173+ await daemon . then (
174+ ( ) => expect . fail ( 'Did not kill process' ) ,
175+ ( err ) => {
176+ expect ( err . killed ) . to . be . true ( )
179177
180- expect ( err . stdout ) . to . not . include ( 'API listening on' )
181- expect ( err . stdout ) . to . not . include ( 'Gateway (read only) listening on' )
182- }
178+ expect ( err . stdout ) . to . not . include ( 'API listening on' )
179+ expect ( err . stdout ) . to . not . include ( 'Gateway (read only) listening on' )
180+ }
181+ )
183182 } )
184183
185184 skipOnWindows ( 'should handle SIGINT gracefully' , async function ( ) {
@@ -211,32 +210,14 @@ describe('daemon', () => {
211210 await ipfs ( 'init' )
212211
213212 const daemon = ipfs ( 'daemon --silent' )
214- const stop = async ( err ) => {
215- daemon . kill ( )
216-
217- if ( err ) {
218- throw err
219- }
220213
221- try {
222- await daemon
223- } catch ( err ) {
224- if ( ! err . killed ) {
225- throw err
226- }
227- }
228- }
214+ setTimeout ( ( ) => {
215+ daemon . kill ( )
216+ } , 5 * 1000 )
229217
230- return new Promise ( ( resolve , reject ) => {
231- daemon . stdout . on ( 'data' , ( data ) => {
232- reject ( new Error ( 'Output was received ' + data . toString ( 'utf8' ) ) )
233- } )
218+ const output = await daemon
234219
235- setTimeout ( ( ) => {
236- resolve ( )
237- } , 5 * 1000 )
238- } )
239- . then ( stop , stop )
220+ expect ( output ) . to . be . empty ( )
240221 } )
241222
242223 it ( 'should present ipfs path help when option help is received' , async function ( ) {
@@ -262,16 +243,16 @@ describe('daemon', () => {
262243 }
263244 } )
264245
265- try {
266- await daemon
267- throw new Error ( 'Did not kill process' )
268- } catch ( err ) {
269- expect ( err . killed ) . to . be . true ( )
246+ await daemon . then (
247+ ( ) => expect . fail ( 'Did not kill process' ) ,
248+ ( err ) => {
249+ expect ( err . killed ) . to . be . true ( )
270250
271- expect ( err . stdout ) . to . include ( `js-ipfs version: ${ pkg . version } ` )
272- expect ( err . stdout ) . to . include ( `System version: ${ os . arch ( ) } /${ os . platform ( ) } ` )
273- expect ( err . stdout ) . to . include ( `Node.js version: ${ process . versions . node } ` )
274- }
251+ expect ( err . stdout ) . to . include ( `js-ipfs version: ${ pkg . version } ` )
252+ expect ( err . stdout ) . to . include ( `System version: ${ os . arch ( ) } /${ os . platform ( ) } ` )
253+ expect ( err . stdout ) . to . include ( `Node.js version: ${ process . versions . node } ` )
254+ }
255+ )
275256 } )
276257
277258 it ( 'should init by default' , async function ( ) {
@@ -290,12 +271,10 @@ describe('daemon', () => {
290271 }
291272 } )
292273
293- try {
294- await daemon
295- throw new Error ( 'Did not kill process' )
296- } catch ( err ) {
297- expect ( err . killed ) . to . be . true ( )
298- }
274+ await daemon . then (
275+ ( ) => expect . fail ( 'Did not kill process' ) ,
276+ ( err ) => expect ( err . killed ) . to . be . true ( )
277+ )
299278
300279 expect ( fs . existsSync ( repoPath ) ) . to . be . true ( )
301280 } )
0 commit comments