1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Use ephemeral port number for MQTT broker

This commit is contained in:
Kazuhito Yokoi 2020-01-14 17:44:56 +09:00
parent 7640bc029c
commit ccc98370eb

View File

@ -29,35 +29,38 @@ var httpNodeRoot = "/api";
var mqttServer; var mqttServer;
var mosca = require('mosca'); var mosca = require('mosca');
var moscaSettings = { var moscaSettings = {
port: 1883, port: parseInt(Math.random() * 16383 + 49152),
persistence: { persistence: {
// Needs for retaining messages. // Needs for retaining messages.
factory: mosca.persistence.Memory factory: mosca.persistence.Memory
} }
}; };
// https://cookbook.nodered.org/ // https://cookbook.nodered.org/
describe('cookbook', function() { describe('cookbook', function () {
beforeEach(function() { beforeEach(function () {
workspace.init(); workspace.init();
}); });
before(function() { before(function () {
browser.call(function() { browser.call(function () {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
mqttServer = new mosca.Server(moscaSettings, function() { mqttServer = new mosca.Server(moscaSettings, function (err) {
if (err) {
reject(err);
} else {
resolve(); resolve();
}
}); });
}); });
}); });
helper.startServer(); helper.startServer();
}); });
after(function() { after(function () {
browser.call(function() { browser.call(function () {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
mqttServer.close(function() { mqttServer.close(function () {
resolve(); resolve();
}); });
}); });
@ -65,20 +68,20 @@ describe('cookbook', function() {
helper.stopServer(); helper.stopServer();
}); });
describe('MQTT', function() { describe('MQTT', function () {
it('Add an MQTT broker to prepare for UI test', function() { it('Add an MQTT broker to prepare for UI test', function () {
var mqttOutNode = workspace.addNode("mqttOut"); var mqttOutNode = workspace.addNode("mqttOut");
mqttOutNode.edit(); mqttOutNode.edit();
mqttConfig.edit(); mqttConfig.edit();
mqttConfig.setServer("localhost"); mqttConfig.setServer("localhost", moscaSettings.port);
mqttConfig.clickOk(); mqttConfig.clickOk();
mqttOutNode.clickOk(); mqttOutNode.clickOk();
workspace.deploy(); workspace.deploy();
}); });
it('Connect to an MQTT broker', function() { it('Connect to an MQTT broker', function () {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut"); var mqttOutNode = workspace.addNode("mqttOut");
@ -112,7 +115,7 @@ describe('cookbook', function() {
// skip this case since it is same as other cases. // skip this case since it is same as other cases.
it.skip('Publish messages to a topic'); it.skip('Publish messages to a topic');
it('Set the topic of a published message', function() { it('Set the topic of a published message', function () {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut"); var mqttOutNode = workspace.addNode("mqttOut");
@ -144,7 +147,7 @@ describe('cookbook', function() {
debugTab.getMessage().should.eql('"22"'); debugTab.getMessage().should.eql('"22"');
}); });
it('Publish a retained message to a topic', function() { it('Publish a retained message to a topic', function () {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut"); var mqttOutNode = workspace.addNode("mqttOut");
@ -182,7 +185,7 @@ describe('cookbook', function() {
// skip this case since it is same as other cases. // skip this case since it is same as other cases.
it.skip('Subscribe to a topic'); it.skip('Subscribe to a topic');
it('Receive a parsed JSON message', function() { it('Receive a parsed JSON message', function () {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut"); var mqttOutNode = workspace.addNode("mqttOut");