Skip to content

Commit

Permalink
fix linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel González García committed Sep 8, 2023
1 parent 9e483dc commit 0e776c9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
9 changes: 7 additions & 2 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,10 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
return this
}

public publishAsync(topic: string, message: string | Buffer): Promise<Packet | undefined>
public publishAsync(
topic: string,
message: string | Buffer,
): Promise<Packet | undefined>
public publishAsync(
topic: string,
message: string | Buffer,
Expand Down Expand Up @@ -1347,7 +1350,9 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
return this
}

public unsubscribeAsync(topic: string | string[]): Promise<Packet | undefined>
public unsubscribeAsync(
topic: string | string[],
): Promise<Packet | undefined>
public unsubscribeAsync(
topic: string | string[],
opts?: IClientSubscribeOptions,
Expand Down
75 changes: 44 additions & 31 deletions test/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export default function abstractTest(server, config) {
it('should emit connect', function _test(done) {
const client = connect()
client.once('connect', (packet: mqtt.IConnackPacket) => {
assert.equal(packet.cmd, "connack")
assert.equal(packet.cmd, 'connack')
client.end(true, (err) => done(err))
})
client.once('error', done)
Expand Down Expand Up @@ -1135,19 +1135,24 @@ export default function abstractTest(server, config) {
})

client.once('connect', () => {
client.publish('a', 'b', pubOpts, (err, packet?: mqtt.Packet) => {
assert.exists(packet)
if (version === 5) {
assert.strictEqual(err.code, pubackReasonCode)
} else {
assert.ifError(err)
}
setImmediate(() => {
client.end(() => {
server2.close(done)
client.publish(
'a',
'b',
pubOpts,
(err, packet?: mqtt.Packet) => {
assert.exists(packet)
if (version === 5) {
assert.strictEqual(err.code, pubackReasonCode)
} else {
assert.ifError(err)
}
setImmediate(() => {
client.end(() => {
server2.close(done)
})
})
})
})
},
)
})
})
})
Expand Down Expand Up @@ -1204,19 +1209,24 @@ export default function abstractTest(server, config) {
})

client.once('connect', () => {
client.publish('a', 'b', pubOpts, (err, packet?: mqtt.Packet) => {
assert.exists(packet)
if (version === 5) {
assert.strictEqual(err.code, pubrecReasonCode)
} else {
assert.ifError(err)
}
setImmediate(() => {
client.end(true, () => {
server2.close(done)
client.publish(
'a',
'b',
pubOpts,
(err, packet?: mqtt.Packet) => {
assert.exists(packet)
if (version === 5) {
assert.strictEqual(err.code, pubrecReasonCode)
} else {
assert.ifError(err)
}
setImmediate(() => {
client.end(true, () => {
server2.close(done)
})
})
})
})
},
)
})
})
})
Expand Down Expand Up @@ -2381,12 +2391,15 @@ export default function abstractTest(server, config) {

//
client.subscribe(testPacket.topic)
client.once('message', (topic, message, packet: mqtt.IPublishPacket) => {
assert.strictEqual(topic, testPacket.topic)
assert.strictEqual(message.toString(), testPacket.payload)
assert.strictEqual(packet.cmd, 'publish')
client.end(true, done)
})
client.once(
'message',
(topic, message, packet: mqtt.IPublishPacket) => {
assert.strictEqual(topic, testPacket.topic)
assert.strictEqual(message.toString(), testPacket.payload)
assert.strictEqual(packet.cmd, 'publish')
client.end(true, done)
},
)

server.once('client', (serverClient) => {
serverClient.on('subscribe', () => {
Expand Down
11 changes: 7 additions & 4 deletions test/client_mqtt5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,13 @@ describe('MQTT 5.0', () => {
}

const client = mqtt.connect(opts)
client.once('disconnect', (disconnectPacket: mqtt.IDisconnectPacket) => {
assert.strictEqual(disconnectPacket.reasonCode, 128)
client.end(true, (err) => done(err))
})
client.once(
'disconnect',
(disconnectPacket: mqtt.IDisconnectPacket) => {
assert.strictEqual(disconnectPacket.reasonCode, 128)
client.end(true, (err) => done(err))
},
)
})

it('pubrec handling custom reason code', function test(done) {
Expand Down

0 comments on commit 0e776c9

Please sign in to comment.