import test from 'ava' ; import { SC , startServer , stopServer } from './helpers/nats_server_control' ; import { connect } from '../src/nats' ; test . before ( async ( t ) => { let server = await startServer ( [ '-DV' ] ) ; t . context = { server : server } ; } ) ; test . after . always ( ( t ) => { stopServer ( ( t . context as SC ) . server ) ; } ) ; test ( 'should not send multiple subscriptions on startup' , async ( t ) => { let subsSeen = 0 ; let subRe = /(\[SUB foo \d\s*\])+/g ; let sc = t . context as SC ; sc . server . stderr . on ( 'data' , function ( data ) { let lines = data . toString ( ) . split ( '\n' ) ; lines . forEach ( ( s ) => { if ( subRe . test ( s ) ) { subsSeen ++ ; } } ) ; } ) ; let nc = await connect ( sc . server . nats ) ; nc . subscribe ( 'foo' , ( ) => { } ) ; await nc . flush ( ) ; await nc . flush ( ) ; nc . close ( ) ; t . is ( subsSeen , 1 ) ; } ) ;