File tree Expand file tree Collapse file tree 2 files changed +27
-19
lines changed Expand file tree Collapse file tree 2 files changed +27
-19
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,11 @@ export class MqttClient extends EventEmitter {
90
90
91
91
// Using this method to clean up the constructor to do options handling
92
92
logger . debug ( `populating internal client options object...` ) ;
93
- this . _options = { ...defaultConnectOptions , ...options }
93
+ this . _options = {
94
+ clientId : defaultClientId ( ) ,
95
+ ...defaultConnectOptions ,
96
+ ...options
97
+ }
94
98
95
99
this . conn = this . _options . customStreamFactory ? this . _options . customStreamFactory ( this . _options ) : connectionFactory ( this . _options ) ;
96
100
@@ -144,10 +148,6 @@ export class MqttClient extends EventEmitter {
144
148
} )
145
149
}
146
150
147
- mergeDefaultOptions ( options : ConnectOptions ) : ConnectOptions {
148
- return { clientId : defaultClientId ( ) , ...defaultConnectOptions , ...options }
149
- }
150
-
151
151
async handleIncomingPacket ( packet : Packet ) : Promise < void > {
152
152
logger . debug ( `handleIncomingPacket packet.cmd=${ packet . cmd } ` ) ;
153
153
switch ( packet . cmd ) {
Original file line number Diff line number Diff line change @@ -44,19 +44,27 @@ test.before('set up aedes broker', async t => {
44
44
} ) ;
45
45
} ) ;
46
46
47
- /* TODO */
48
- test ( 'should send a CONNECT packet to the broker and receive a CONNACK' , async t => {
49
- const client = await connect ( {
47
+ test ( 'should send a CONNECT packet to the broker and receive a CONNACK' , ( t ) => {
48
+ t . plan ( 0 )
49
+ const clientId = 'basic-connect-test'
50
+
51
+ let resolveClientConnected
52
+ const clientConnectedPromise = new Promise ( ( resolve ) => {
53
+ resolveClientConnected = resolve
54
+ } )
55
+
56
+ const clientConnectedListener = ( client ) => {
57
+ if ( client . id === clientId ) {
58
+ t . context . broker . removeListener ( 'client' , clientConnectedListener )
59
+ resolveClientConnected ( )
60
+ }
61
+ }
62
+ t . context . broker . on ( 'client' , clientConnectedListener )
63
+
64
+ const clientPromise = connect ( {
50
65
brokerUrl : 'mqtt://localhost' ,
51
- } ) ;
52
- t . assert ( ! ! client ) ;
53
- } ) ;
66
+ clientId
67
+ } )
54
68
55
- /**
56
- * 1) Send a Connect packet
57
- * 2) writeToStream returns false and emits an error on this.conn('error')
58
- *
59
- * We shouldn't be throwing away the whole client because 1 packet failed.
60
- *
61
- * UPDATE: matteo advises otherwise: https://github.com/mqttjs/mqtt-packet/issues/126#issuecomment-1029373619
62
- */
69
+ return Promise . all ( [ clientConnectedPromise , clientPromise ] )
70
+ } )
You can’t perform that action at this time.
0 commit comments