HiveMQ MQTT Module
This module allows automatic start up of HiveMQ's docker container within Jest suites, to enable programmatic testing of JavaScript based MQTT client applications.
Install
npm install @testcontainers/hivemq --save-dev
Resources
Please make sure to check out the hivemq-docs for the Community Edition.
Info
We are working to support the HiveMQ Enterprise Edition as outlined in the Java Test Containers Module.
Examples
it("should connect to HiveMQ Community Edition via MQTT.js", (done) => {
new HiveMQContainer().start().then((hiveMQContainer) => {
const testMqttClient = mqtt.connect(hiveMQContainer.getConnectionString());
testMqttClient.on("message", (topic, message) => {
expect(message.toString()).toEqual("Test Message");
testMqttClient.end();
done();
});
testMqttClient.on("connect", () => {
testMqttClient.subscribe("test", (error) => {
if (!error) {
testMqttClient.publish("test", "Test Message");
}
});
});
});
});