-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pubsub): migrate from paho-mqtt to mqtt.js
- Loading branch information
1 parent
677f466
commit e947379
Showing
8 changed files
with
229 additions
and
3,001 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const mqttClientMockCache: Record<string, any> = {}; | ||
|
||
const mockMqttClient = (clientId: string) => { | ||
if (mqttClientMockCache[clientId]) { | ||
return mqttClientMockCache[clientId]; | ||
} | ||
|
||
const eventHandlers: Record<string, (...args: any[]) => void> = {}; | ||
|
||
const client = { | ||
on: jest.fn((event, handler) => { | ||
eventHandlers[event] = handler; | ||
}), | ||
publish: jest.fn((topic, message) => { | ||
eventHandlers.message(topic, message); | ||
}), | ||
subscribe: jest.fn(), | ||
unsubscribe: jest.fn(), | ||
connected: true, | ||
end: jest.fn(), | ||
}; | ||
|
||
mqttClientMockCache[clientId] = client; | ||
|
||
return client; | ||
}; | ||
|
||
const mqtt = { | ||
connectAsync: jest.fn((_, { clientId }) => | ||
Promise.resolve(mockMqttClient(clientId)), | ||
), | ||
}; | ||
|
||
export default mqtt; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.