From ccc98370eb804b7242c5e012eceb52c4d0d2313e Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Tue, 14 Jan 2020 17:44:56 +0900 Subject: [PATCH] Use ephemeral port number for MQTT broker --- .../specs/scenario/cookbook_mqtt_uispec.js | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/test/editor/specs/scenario/cookbook_mqtt_uispec.js b/test/editor/specs/scenario/cookbook_mqtt_uispec.js index 887d9735c..655074750 100644 --- a/test/editor/specs/scenario/cookbook_mqtt_uispec.js +++ b/test/editor/specs/scenario/cookbook_mqtt_uispec.js @@ -29,35 +29,38 @@ var httpNodeRoot = "/api"; var mqttServer; var mosca = require('mosca'); var moscaSettings = { - port: 1883, + port: parseInt(Math.random() * 16383 + 49152), persistence: { // Needs for retaining messages. factory: mosca.persistence.Memory } }; - // https://cookbook.nodered.org/ -describe('cookbook', function() { - beforeEach(function() { +describe('cookbook', function () { + beforeEach(function () { workspace.init(); }); - before(function() { - browser.call(function() { - return new Promise(function(resolve, reject) { - mqttServer = new mosca.Server(moscaSettings, function() { - resolve(); + before(function () { + browser.call(function () { + return new Promise(function (resolve, reject) { + mqttServer = new mosca.Server(moscaSettings, function (err) { + if (err) { + reject(err); + } else { + resolve(); + } }); }); }); helper.startServer(); }); - after(function() { - browser.call(function() { - return new Promise(function(resolve, reject) { - mqttServer.close(function() { + after(function () { + browser.call(function () { + return new Promise(function (resolve, reject) { + mqttServer.close(function () { resolve(); }); }); @@ -65,20 +68,20 @@ describe('cookbook', function() { helper.stopServer(); }); - describe('MQTT', function() { - it('Add an MQTT broker to prepare for UI test', function() { + describe('MQTT', function () { + it('Add an MQTT broker to prepare for UI test', function () { var mqttOutNode = workspace.addNode("mqttOut"); mqttOutNode.edit(); mqttConfig.edit(); - mqttConfig.setServer("localhost"); + mqttConfig.setServer("localhost", moscaSettings.port); mqttConfig.clickOk(); mqttOutNode.clickOk(); workspace.deploy(); }); - it('Connect to an MQTT broker', function() { + it('Connect to an MQTT broker', function () { var injectNode = workspace.addNode("inject"); var mqttOutNode = workspace.addNode("mqttOut"); @@ -112,7 +115,7 @@ describe('cookbook', function() { // skip this case since it is same as other cases. 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 mqttOutNode = workspace.addNode("mqttOut"); @@ -144,7 +147,7 @@ describe('cookbook', function() { 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 mqttOutNode = workspace.addNode("mqttOut"); @@ -182,7 +185,7 @@ describe('cookbook', function() { // skip this case since it is same as other cases. 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 mqttOutNode = workspace.addNode("mqttOut");