From b7818b3512b07cde7e5973c703d021122051c2be Mon Sep 17 00:00:00 2001 From: biancode Date: Sun, 16 Jun 2024 17:43:05 +0200 Subject: [PATCH] refactor(test): clean up cbs and fix IO Node tests --- CHANGELOG.md | 2 +- HISTORY.md | 7 +- package-lock.json | 18 +- package.json | 9 +- src/modbus-io-config.js | 77 ++--- test/helper/test-helper-port.js | 15 +- test/resources/device.json | 235 +++----------- test/resources/deviceCopy.json | 47 +++ test/units/flows/modbus-getter-flows.js | 301 +++++++++--------- test/units/flows/modbus-io-config-flows.js | 295 ++++++++--------- .../flows/modbus-response-filter-flows.js | 2 +- test/units/modbus-flex-getter-test.js | 16 - test/units/modbus-flex-sequencer-test.js | 2 - test/units/modbus-flex-write-test.js | 22 -- test/units/modbus-getter-test.js | 16 - test/units/modbus-io-config-test.js | 110 +++++-- test/units/modbus-queue-info-test.js | 8 - test/units/modbus-read-test.js | 14 - test/units/modbus-response-filter-test.js | 8 +- test/units/modbus-server-test.js | 6 - test/units/modbus-write-test.js | 12 - yarn.lock | 12 +- 22 files changed, 557 insertions(+), 677 deletions(-) create mode 100644 test/resources/deviceCopy.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cfe4076..87198c8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# [5.40.0](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.27.2...v5.40.0) (2024-06-15) +# [5.40.0](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.27.2...v5.40.0) (2024-06-16) ### Bug Fixes diff --git a/HISTORY.md b/HISTORY.md index 202094e0..3ef44ac9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ # Version History ## Node-RED v3.x versions: +* Node.js 20.x will be supported with v5.40+ * Node.js 18.x will be supported with v5.22+ * Node.js 16.x will be supported with v5.22+ @@ -17,7 +18,7 @@ ## Node-RED v0.x versions: * Node.js 10.x is supported with v4.x -* Node.js 8.x is supported with v3.x -* Node.js 6.x is supported with v2.x -* Node.js 4.x is supported with v1.x +* Node.js 8.x is supported with v3.x +* Node.js 6.x is supported with v2.x +* Node.js 4.x is supported with v1.x diff --git a/package-lock.json b/package-lock.json index 2e818266..5739e7d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14536,9 +14536,9 @@ } }, "node_modules/parse-json/node_modules/type-fest": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.20.0.tgz", - "integrity": "sha512-MBh+PHUHHisjXf4tlx0CFWoMdjx8zCMLJHOjnV1prABYZFHqtFOyauCIK2/7w4oIfwkF8iNhLtnJEfVY2vn3iw==", + "version": "4.20.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.20.1.tgz", + "integrity": "sha512-R6wDsVsoS9xYOpy8vgeBlqpdOyzJ12HNfQhC/aAKWM3YoCV9TtunJzh/QpkMgeDhkoynDcw5f1y+qF9yc/HHyg==", "dev": true, "engines": { "node": ">=16" @@ -15322,9 +15322,9 @@ } }, "node_modules/read-package-up/node_modules/type-fest": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.20.0.tgz", - "integrity": "sha512-MBh+PHUHHisjXf4tlx0CFWoMdjx8zCMLJHOjnV1prABYZFHqtFOyauCIK2/7w4oIfwkF8iNhLtnJEfVY2vn3iw==", + "version": "4.20.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.20.1.tgz", + "integrity": "sha512-R6wDsVsoS9xYOpy8vgeBlqpdOyzJ12HNfQhC/aAKWM3YoCV9TtunJzh/QpkMgeDhkoynDcw5f1y+qF9yc/HHyg==", "dev": true, "engines": { "node": ">=16" @@ -15481,9 +15481,9 @@ } }, "node_modules/read-pkg/node_modules/type-fest": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.20.0.tgz", - "integrity": "sha512-MBh+PHUHHisjXf4tlx0CFWoMdjx8zCMLJHOjnV1prABYZFHqtFOyauCIK2/7w4oIfwkF8iNhLtnJEfVY2vn3iw==", + "version": "4.20.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.20.1.tgz", + "integrity": "sha512-R6wDsVsoS9xYOpy8vgeBlqpdOyzJ12HNfQhC/aAKWM3YoCV9TtunJzh/QpkMgeDhkoynDcw5f1y+qF9yc/HHyg==", "dev": true, "engines": { "node": ">=16" diff --git a/package.json b/package.json index f11d6a68..7e55e434 100644 --- a/package.json +++ b/package.json @@ -71,13 +71,13 @@ "test:slow": "npm run lint && mocha ./test --recursive --reporter dot", "test:verbose": "npm run lint && mocha ./test --recursive", "test:withStop": "npm run lint && mocha ./test --recursive --bail", - "test:e2e": "npm run lint && mocha ./test/core/modbus-io-core-test.js --parallel --recursive --reporter dot --timeout 100000", "lint": "standard --fix", + "test:e2e": "npm run lint && mocha './test/e2e/*e2e-test.js' --parallel --recursive --reporter dot --timeout 100000", "test:units": "npm run lint && mocha './test/units/*-test.js' --parallel --recursive", "test:core": "npm run lint && mocha './test/core/*-test.js' --parallel --recursive", "test-nyc": "nyc --reporter=html --reporter=text mocha --recursive", "test-npx": "npx nyc@latest --reporter=html --reporter=text mocha ./test --parallel --recursive --reporter dot --timeout 10000", - "test-with-coverage": "nyc --reporter=lcovonly mocha --recursive --timeout 7000 -R spec && cat ./coverage/lcov.info | codacy-coverage --token $CODACY_COVERAGE_TOKEN && rm -rf ./coverage", + "test-with-coverage": "nyc --reporter=lcovonly mocha --recursive -R spec && cat ./coverage/lcov.info | codacy-coverage --token $CODACY_COVERAGE_TOKEN && rm -rf ./coverage", "coverage": "npm run lint && nyc mocha ./test --parallel --recursive --reporter dot --timeout 10000", "coverage-nyc": "npm run lint && nyc report --reporter=text-lcov | coveralls", "build": "npm run lint && gulp", @@ -134,7 +134,9 @@ "test": "test" }, "standard": { - "env": ["mocha"], + "env": [ + "mocha" + ], "globals": [ "chai", "expect", @@ -148,6 +150,7 @@ "modbus/", "docs", "extras", + "test/resources/**", "test/e2e/flows/**", "test/integrations/flows/**", "test/units/flows/**" diff --git a/src/modbus-io-config.js b/src/modbus-io-config.js index 89e223be..1b57c5ed 100644 --- a/src/modbus-io-config.js +++ b/src/modbus-io-config.js @@ -6,6 +6,7 @@ @author Klaus Landsdorf (Bianco Royal) */ + module.exports = function (RED) { 'use strict' // SOURCE-MAP-REQUIRED @@ -25,29 +26,45 @@ module.exports = function (RED) { const node = this node.setMaxListeners(UNLIMITED_LISTENERS) node.lastUpdatedAt = null - const lineReader = new coreIO.LineByLineReader(node.path) + + if (!fs.existsSync(node.path)) { + coreIO.internalDebug('IO File Not Found ' + node.path) + node.warn('Modbus IO File Not Found ' + node.path) + return + } + + node.lineReader = new coreIO.LineByLineReader(node.path) coreIO.internalDebug('Read IO File ' + node.path) node.configData = [] - lineReader.on('error', function (err) { - coreIO.internalDebug(err.message) - }) - - lineReader.on('line', function (line) { - if (line) { - node.configData.push(line) - // node.configData.push(JSON.parse(line)) - } - }) + function setLineReaderEvents () { + node.lineReader.removeAllListeners() + + node.lineReader.on('error', function (err) { + coreIO.internalDebug(err.message) + }) + + node.lineReader.on('line', function (line) { + if (line) { + node.configData.push(line) + } + }) + + node.lineReader.on('end', function () { + node.lastUpdatedAt = Date.now() + coreIO.internalDebug('Read IO Done From File ' + node.path) + node.warn({ + payload: coreIO.allValueNamesFromIOFile(node), + name: 'Modbus Value Names From IO File', + path: node.path + }) + node.emit('updatedConfig', node.configData) + }) - lineReader.on('end', function () { - node.lastUpdatedAt = Date.now() - coreIO.internalDebug('Read IO Done From File ' + node.path) - node.warn({ payload: coreIO.allValueNamesFromIOFile(node), name: 'Modbus Value Names From IO File', path: node.path }) - node.emit('updatedConfig', node.configData) - }) + coreIO.internalDebug('Loading IO File Started For ' + node.path) + } - coreIO.internalDebug('Loading IO File Started For ' + node.path) + setLineReaderEvents() node.watcher = fs.watchFile(node.path, (curr, prev) => { coreIO.internalDebug(`the current mtime is: ${curr.mtime}`) @@ -57,25 +74,9 @@ module.exports = function (RED) { coreIO.internalDebug('Reload IO File ' + node.path) node.configData = [] delete node.lastUpdatedAt - - const lineReader = new coreIO.LineByLineReader(node.path) - lineReader.on('error', function (err) { - coreIO.internalDebug(err.message) - }) - - lineReader.on('line', function (line) { - if (line) { - node.configData.push(JSON.parse(line)) - } - }) - - lineReader.on('end', function () { - node.lastUpdatedAt = Date.now() - coreIO.internalDebug('Reload IO Done From File ' + node.path) - node.warn({ payload: coreIO.allValueNamesFromIOFile(node), name: 'Modbus Value Names From IO File', path: node.path }) - node.emit('updatedConfig', node.configData) - }) - + node.lineReader.removeAllListeners() + node.lineReader = new coreIO.LineByLineReader(node.path) + setLineReaderEvents() coreIO.internalDebug('Reloading IO File Started For ' + node.path) } }) @@ -83,6 +84,8 @@ module.exports = function (RED) { node.on('close', function (done) { fs.unwatchFile(node.path) node.watcher.stop() + node.lineReader.removeAllListeners() + node.removeAllListeners() done() }) } diff --git a/test/helper/test-helper-port.js b/test/helper/test-helper-port.js index fd45e3e8..c7ef356b 100644 --- a/test/helper/test-helper-port.js +++ b/test/helper/test-helper-port.js @@ -39,20 +39,21 @@ class PortHelper { getPort = async () => { if (this.startPort === 0) { - this.startPort = this.getRandomArbitrary(15000, 40000) + this.startPort = this.getRandomArbitrary(30000, 50000) } - let port = this.startPort++ + this.startPort = this.startPort + 3 - if (this.startPort >= 65535) { - this.startPort = 20000 + if (this.startPort >= 50000) { + this.startPort = this.getRandomArbitrary(10000, 30000) } - if (global.portList.includes(port)) { - port = await this.getPort() + if (global.portList.includes(this.startPort)) { + this.startPort = await this.getPort() } - return port + global.portList.push(this.startPort) + return this.startPort } tryListen (port, maxPort, hostname, callback) { diff --git a/test/resources/device.json b/test/resources/device.json index bf95397c..fe547b4a 100644 --- a/test/resources/device.json +++ b/test/resources/device.json @@ -1,188 +1,47 @@ -{ - "name": "Modbus Holding Registers", - "valueAddress": "%IW0" -} -{ - "name": "iCountDummyBorder", - "valueAddress": "%IW0" -} -{ - "name": "iCountDummyMirror", - "valueAddress": "%IW1" -} -{ - "name": "iAddDummyMirror", - "valueAddress": "%IW2" -} -{ - "name": "iAddDummyBorder", - "valueAddress": "%IW3" -} -{ - "name": "bReset", - "valueAddress": "%IX8.0" -} -{ - "name": "fMyValue", - "valueAddress": "%IW5" -} -{ - "name": "dMyVar", - "valueAddress": "%IW7" -} -{ - "name": "fNextVar", - "valueAddress": "%IW11" -} -{ - "name": "Modbus Input Registers", - "valueAddress": "%QW0" -} -{ - "name": "iTraceDummy", - "valueAddress": "%QW0" -} -{ - "name": "iCountDummy", - "valueAddress": "%QW1" -} -{ - "name": "iAddDummy", - "valueAddress": "%QW2" -} -{ - "name": "iTraceDummy2", - "valueAddress": "%QW3" -} -{ - "name": "bOperationActive", - "valueAddress": "%QX8.0" -} -{ - "name": "bOrderActive", - "valueAddress": "%QX8.1" -} -{ - "name": "bRecipeActive", - "valueAddress": "%QX8.2" -} -{ - "name": "bInfoActive", - "valueAddress": "%QX8.3" -} -{ - "name": "bServiceActive", - "valueAddress": "%QX8.4" -} -{ - "name": "bSimulationActive", - "valueAddress": "%QX8.5" -} -{ - "name": "bHideOrderSubM", - "valueAddress": "%QX8.6" -} -{ - "name": "bHideInfoSubM", - "valueAddress": "%QX8.7" -} -{ - "name": "bHideServiceSubM", - "valueAddress": "%QX9.0" -} -{ - "name": "bMoveOverOperation", - "valueAddress": "%QX9.1" -} -{ - "name": "bMoveOverRecipes", - "valueAddress": "%QX9.2" -} -{ - "name": "bMoveOverSimulation", - "valueAddress": "%QX9.3" -} -{ - "name": "bxLeft", - "valueAddress": "%QX9.5" -} -{ - "name": "bxRight", - "valueAddress": "%QX9.6" -} -{ - "name": "bSubInfo1", - "valueAddress": "%QX10.0" -} -{ - "name": "bSubInfo2", - "valueAddress": "%QX10.1" -} -{ - "name": "bSubInfo3", - "valueAddress": "%QX10.2" -} -{ - "name": "bSubInfo4", - "valueAddress": "%QX10.3" -} -{ - "name": "bSubOrder1", - "valueAddress": "%QX10.4" -} -{ - "name": "bSubOrder2", - "valueAddress": "%QX10.5" -} -{ - "name": "bSubService1", - "valueAddress": "%QX10.6" -} -{ - "name": "bSubService2", - "valueAddress": "%QX10.7" -} -{ - "name": "bSubService3", - "valueAddress": "%QX11.0" -} -{ - "name": "dwColorSelection", - "valueAddress": "%QW8" -} -{ - "name": "dwColorMoveOver", - "valueAddress": "%QW10" -} -{ - "name": "dwColorOperation", - "valueAddress": "%QW12" -} -{ - "name": "dwColorOrder", - "valueAddress": "%QW14" -} -{ - "name": "dwColorRecipes", - "valueAddress": "%QW16" -} -{ - "name": "dwColorInfo", - "valueAddress": "%QW18" -} -{ - "name": "dwColorService", - "valueAddress": "%QW20" -} -{ - "name": "dwColorSimulation", - "valueAddress": "%QW22" -} -{ - "name": "iCountDummyBorderValue", - "valueAddress": "%QW24" -} -{ - "name": "iAddDummyBorderValue", - "valueAddress": "%QW25" -} +{"name":"Modbus Holding Registers","valueAddress":"%IW0"} +{"name":"iCountDummyBorder","valueAddress":"%IW0"} +{"name":"iCountDummyMirror","valueAddress":"%IW1"} +{"name":"iAddDummyMirror","valueAddress":"%IW2"} +{"name":"iAddDummyBorder","valueAddress":"%IW3"} +{"name":"bReset","valueAddress":"%IX8.0"} +{"name":"fMyValue","valueAddress":"%IW5"} +{"name":"dMyVar","valueAddress":"%IW7"} +{"name":"fNextVar","valueAddress":"%IW11"} +{"name":"Modbus Input Registers","valueAddress":"%QW0"} +{"name":"iTraceDummy","valueAddress":"%QW0"} +{"name":"iCountDummy","valueAddress":"%QW1"} +{"name":"iAddDummy","valueAddress":"%QW2"} +{"name":"iTraceDummy2","valueAddress":"%QW3"} +{"name":"bOperationActive","valueAddress":"%QX8.0"} +{"name":"bOrderActive","valueAddress":"%QX8.1"} +{"name":"bRecipeActive","valueAddress":"%QX8.2"} +{"name":"bInfoActive","valueAddress":"%QX8.3"} +{"name":"bServiceActive","valueAddress":"%QX8.4"} +{"name":"bSimulationActive","valueAddress":"%QX8.5"} +{"name":"bHideOrderSubM","valueAddress":"%QX8.6"} +{"name":"bHideInfoSubM","valueAddress":"%QX8.7"} +{"name":"bHideServiceSubM","valueAddress":"%QX9.0"} +{"name":"bMoveOverOperation","valueAddress":"%QX9.1"} +{"name":"bMoveOverRecipes","valueAddress":"%QX9.2"} +{"name":"bMoveOverSimulation","valueAddress":"%QX9.3"} +{"name":"bxLeft","valueAddress":"%QX9.5"} +{"name":"bxRight","valueAddress":"%QX9.6"} +{"name":"bSubInfo1","valueAddress":"%QX10.0"} +{"name":"bSubInfo2","valueAddress":"%QX10.1"} +{"name":"bSubInfo3","valueAddress":"%QX10.2"} +{"name":"bSubInfo4","valueAddress":"%QX10.3"} +{"name":"bSubOrder1","valueAddress":"%QX10.4"} +{"name":"bSubOrder2","valueAddress":"%QX10.5"} +{"name":"bSubService1","valueAddress":"%QX10.6"} +{"name":"bSubService2","valueAddress":"%QX10.7"} +{"name":"bSubService3","valueAddress":"%QX11.0"} +{"name":"dwColorSelection","valueAddress":"%QW8"} +{"name":"dwColorMoveOver","valueAddress":"%QW10"} +{"name":"dwColorOperation","valueAddress":"%QW12"} +{"name":"dwColorOrder","valueAddress":"%QW14"} +{"name":"dwColorRecipes","valueAddress":"%QW16"} +{"name":"dwColorInfo","valueAddress":"%QW18"} +{"name":"dwColorService","valueAddress":"%QW20"} +{"name":"dwColorSimulation","valueAddress":"%QW22"} +{"name":"iCountDummyBorderValue","valueAddress":"%QW24"} +{"name":"iAddDummyBorderValue","valueAddress":"%QW25"} diff --git a/test/resources/deviceCopy.json b/test/resources/deviceCopy.json new file mode 100644 index 00000000..fe547b4a --- /dev/null +++ b/test/resources/deviceCopy.json @@ -0,0 +1,47 @@ +{"name":"Modbus Holding Registers","valueAddress":"%IW0"} +{"name":"iCountDummyBorder","valueAddress":"%IW0"} +{"name":"iCountDummyMirror","valueAddress":"%IW1"} +{"name":"iAddDummyMirror","valueAddress":"%IW2"} +{"name":"iAddDummyBorder","valueAddress":"%IW3"} +{"name":"bReset","valueAddress":"%IX8.0"} +{"name":"fMyValue","valueAddress":"%IW5"} +{"name":"dMyVar","valueAddress":"%IW7"} +{"name":"fNextVar","valueAddress":"%IW11"} +{"name":"Modbus Input Registers","valueAddress":"%QW0"} +{"name":"iTraceDummy","valueAddress":"%QW0"} +{"name":"iCountDummy","valueAddress":"%QW1"} +{"name":"iAddDummy","valueAddress":"%QW2"} +{"name":"iTraceDummy2","valueAddress":"%QW3"} +{"name":"bOperationActive","valueAddress":"%QX8.0"} +{"name":"bOrderActive","valueAddress":"%QX8.1"} +{"name":"bRecipeActive","valueAddress":"%QX8.2"} +{"name":"bInfoActive","valueAddress":"%QX8.3"} +{"name":"bServiceActive","valueAddress":"%QX8.4"} +{"name":"bSimulationActive","valueAddress":"%QX8.5"} +{"name":"bHideOrderSubM","valueAddress":"%QX8.6"} +{"name":"bHideInfoSubM","valueAddress":"%QX8.7"} +{"name":"bHideServiceSubM","valueAddress":"%QX9.0"} +{"name":"bMoveOverOperation","valueAddress":"%QX9.1"} +{"name":"bMoveOverRecipes","valueAddress":"%QX9.2"} +{"name":"bMoveOverSimulation","valueAddress":"%QX9.3"} +{"name":"bxLeft","valueAddress":"%QX9.5"} +{"name":"bxRight","valueAddress":"%QX9.6"} +{"name":"bSubInfo1","valueAddress":"%QX10.0"} +{"name":"bSubInfo2","valueAddress":"%QX10.1"} +{"name":"bSubInfo3","valueAddress":"%QX10.2"} +{"name":"bSubInfo4","valueAddress":"%QX10.3"} +{"name":"bSubOrder1","valueAddress":"%QX10.4"} +{"name":"bSubOrder2","valueAddress":"%QX10.5"} +{"name":"bSubService1","valueAddress":"%QX10.6"} +{"name":"bSubService2","valueAddress":"%QX10.7"} +{"name":"bSubService3","valueAddress":"%QX11.0"} +{"name":"dwColorSelection","valueAddress":"%QW8"} +{"name":"dwColorMoveOver","valueAddress":"%QW10"} +{"name":"dwColorOperation","valueAddress":"%QW12"} +{"name":"dwColorOrder","valueAddress":"%QW14"} +{"name":"dwColorRecipes","valueAddress":"%QW16"} +{"name":"dwColorInfo","valueAddress":"%QW18"} +{"name":"dwColorService","valueAddress":"%QW20"} +{"name":"dwColorSimulation","valueAddress":"%QW22"} +{"name":"iCountDummyBorderValue","valueAddress":"%QW24"} +{"name":"iAddDummyBorderValue","valueAddress":"%QW25"} diff --git a/test/units/flows/modbus-getter-flows.js b/test/units/flows/modbus-getter-flows.js index e92c92e1..780cda28 100644 --- a/test/units/flows/modbus-getter-flows.js +++ b/test/units/flows/modbus-getter-flows.js @@ -2,7 +2,8 @@ const helperExtensions = require('../../helper/test-helper-extensions') module.exports = { - testGetterWithoutClientConfigFlow: helperExtensions.cleanFlowPositionData([ + testGetterWithoutClientConfigFlow: helperExtensions.cleanFlowPositionData( + [ { id: '1243c51545a330d6', type: 'tab', @@ -36,9 +37,11 @@ module.exports = { [] ] } - ]), + ] + ), - testGetterFlowWithInjectIo: helperExtensions.cleanFlowPositionData([ + testGetterFlowWithInjectIo: helperExtensions.cleanFlowPositionData( + [ { id: 'd6e437043c8cf4a4', type: 'tab', @@ -84,7 +87,7 @@ module.exports = { dataType: 'Coil', adr: '0', quantity: '10', - server: '92e7bf63.2efd7', + server: '92e7bf63.2efe9', useIOFile: true, ioFile: 'd43501866bf390b6', useIOForPayload: false, @@ -129,7 +132,7 @@ module.exports = { ] }, { - id: '92e7bf63.2efd7', + id: '92e7bf63.2efe9', type: 'modbus-client', z: 'd6e437043c8cf4a4', name: 'ModbusServer', @@ -161,13 +164,15 @@ module.exports = { type: 'modbus-io-config', z: 'd6e437043c8cf4a4', name: 'TestIOFile', - path: './test/units/resources/device.json', + path: './test/resources/device.json', format: 'utf8', addressOffset: '' } - ]), + ] + ), - testGetterFlow: helperExtensions.cleanFlowPositionData([ + testGetterFlow: helperExtensions.cleanFlowPositionData( + [ { id: '9e0ce71e20ca8f6d', type: 'tab', @@ -275,9 +280,11 @@ module.exports = { format: 'utf8', addressOffset: '' } - ]), + ] + ), - testGetterWithClientFlow: helperExtensions.cleanFlowPositionData([ + testGetterWithClientFlow: helperExtensions.cleanFlowPositionData( + [ { id: '0dfcc7e634544d53', type: 'tab', @@ -363,142 +370,148 @@ module.exports = { reconnectTimeout: '2000', parallelUnitIdsAllowed: true } - ]), + ] + ), - testInjectGetterWithClientFlow: helperExtensions.cleanFlowPositionData([ - { - id: 'ae4a7c8ae3cc71e0', - type: 'tab', - label: 'Test Inject Getter With Client Flow', - disabled: false, - info: '', - env: [] - }, - { - id: '445454e4.968564', - type: 'modbus-server', - z: 'ae4a7c8ae3cc71e0', - name: '', - logEnabled: true, - hostname: '127.0.0.1', - serverPort: '7272', - responseDelay: 100, - delayUnit: 'ms', - coilsBufferSize: 10000, - holdingBufferSize: 10000, - inputBufferSize: 10000, - discreteBufferSize: 10000, - showErrors: false, - x: 220, - y: 80, - wires: [ - [], - [], - [], - [], - [] - ] - }, - { - id: 'cea01c8.36f8f6', - type: 'modbus-getter', - z: 'ae4a7c8ae3cc71e0', - name: '', - showStatusActivities: true, - showErrors: true, - logIOActivities: false, - unitid: '', - dataType: 'Coil', - adr: '0', - quantity: '10', - server: '92e7bf63.2efd7', - useIOFile: false, - ioFile: '', - useIOForPayload: false, - emptyMsgOnFail: false, - keepMsgProperties: false, - x: 400, - y: 180, - wires: [ - [ - 'h1' + testInjectGetterWithClientFlow: helperExtensions.cleanFlowPositionData( + [ + { + "id": "ae4a7c8ae3cc71e0", + "type": "tab", + "label": "Test Inject Getter With Client Flow", + "disabled": false, + "info": "", + "env": [] + }, + { + "id": "445454e4.968564", + "type": "modbus-server", + "z": "ae4a7c8ae3cc71e0", + "name": "", + "logEnabled": true, + "hostname": "127.0.0.1", + "serverPort": "7272", + "responseDelay": 100, + "delayUnit": "ms", + "coilsBufferSize": 10000, + "holdingBufferSize": 10000, + "inputBufferSize": 10000, + "discreteBufferSize": 10000, + "showErrors": false, + "x": 220, + "y": 80, + "wires": [ + [], + [], + [], + [], + [] + ] + }, + { + "id": "cea01c8.36f8f6", + "type": "modbus-getter", + "z": "ae4a7c8ae3cc71e0", + "name": "", + "showStatusActivities": true, + "showErrors": true, + "showWarnings": true, + "logIOActivities": false, + "unitid": "", + "dataType": "Coil", + "adr": "0", + "quantity": "10", + "server": "92e7bf63.2efc8", + "useIOFile": false, + "ioFile": "", + "useIOForPayload": false, + "emptyMsgOnFail": false, + "keepMsgProperties": false, + "delayOnStart": false, + "startDelayTime": "", + "x": 400, + "y": 180, + "wires": [ + [ + "h1" + ], + [] + ] + }, + { + "id": "h1", + "type": "helper", + "z": "ae4a7c8ae3cc71e0", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "payload", + "targetType": "msg", + "statusVal": "", + "statusType": "auto", + "x": 610, + "y": 180, + "wires": [] + }, + { + "id": "a75e0ccf.e16628", + "type": "inject", + "z": "ae4a7c8ae3cc71e0", + "name": "", + "props": [ + { + "p": "payload" + }, + { + "p": "topic", + "vt": "str" + } ], - [] - ] - }, - { - id: 'h1', - type: 'helper', - z: 'ae4a7c8ae3cc71e0', - name: '', - active: true, - tosidebar: true, - console: false, - tostatus: false, - complete: 'payload', - targetType: 'msg', - statusVal: '', - statusType: 'auto', - x: 610, - y: 180, - wires: [] - }, - { - id: 'a75e0ccf.e16628', - type: 'inject', - z: 'ae4a7c8ae3cc71e0', - name: '', - props: [ - { - p: 'payload' - }, - { - p: 'topic', - vt: 'str' - } - ], - repeat: '1', - crontab: '', - once: true, - onceDelay: 0.1, - topic: '', - payload: '', - payloadType: 'date', - x: 210, - y: 180, - wires: [ - [ - 'cea01c8.36f8f6' + "repeat": "1", + "crontab": "", + "once": true, + "onceDelay": 0.1, + "topic": "", + "payload": "", + "payloadType": "date", + "x": 210, + "y": 180, + "wires": [ + [ + "cea01c8.36f8f6" + ] ] - ] - }, - { - id: '92e7bf63.2efd7', - type: 'modbus-client', - name: 'ModbusServer', - clienttype: 'tcp', - bufferCommands: true, - stateLogEnabled: true, - queueLogEnabled: false, - failureLogEnabled: false, - tcpHost: '127.0.0.1', - tcpPort: '7272', - tcpType: 'DEFAULT', - serialPort: '/dev/ttyUSB', - serialType: 'RTU-BUFFERD', - serialBaudrate: '9600', - serialDatabits: '8', - serialStopbits: '1', - serialParity: 'none', - serialConnectionDelay: '100', - serialAsciiResponseStartDelimiter: '', - unit_id: '1', - commandDelay: '1', - clientTimeout: '100', - reconnectOnTimeout: false, - reconnectTimeout: '200', - parallelUnitIdsAllowed: true - } - ]) + }, + { + "id": "92e7bf63.2efc8", + "type": "modbus-client", + "name": "ModbusServer", + "clienttype": "tcp", + "bufferCommands": true, + "stateLogEnabled": true, + "queueLogEnabled": false, + "failureLogEnabled": false, + "tcpHost": "127.0.0.1", + "tcpPort": "7272", + "tcpType": "DEFAULT", + "serialPort": "/dev/ttyUSB", + "serialType": "RTU-BUFFERD", + "serialBaudrate": "9600", + "serialDatabits": "8", + "serialStopbits": "1", + "serialParity": "none", + "serialConnectionDelay": "100", + "serialAsciiResponseStartDelimiter": "", + "unit_id": "1", + "commandDelay": "1", + "clientTimeout": "100", + "reconnectOnTimeout": false, + "reconnectTimeout": "200", + "parallelUnitIdsAllowed": true + } + ] + ) } diff --git a/test/units/flows/modbus-io-config-flows.js b/test/units/flows/modbus-io-config-flows.js index 5a42ac69..d800e51e 100644 --- a/test/units/flows/modbus-io-config-flows.js +++ b/test/units/flows/modbus-io-config-flows.js @@ -4,171 +4,174 @@ module.exports = { testReadWithClientIoFlow: helperExtensions.cleanFlowPositionData( [ { - "id": "7ecaf10e98444c51", - "type": "tab", - "label": "Test Read with Client IO Flow", - "disabled": false, - "info": "", - "env": [] + "id": "7ecaf10e98444c51", + "type": "tab", + "label": "Test Read with Client IO Flow", + "disabled": false, + "info": "", + "env": [] }, { - "id": "94d59eaf66811f1d", - "type": "modbus-server", - "z": "7ecaf10e98444c51", - "name": "", - "logEnabled": true, - "hostname": "127.0.0.1", - "serverPort": "5412", - "responseDelay": 100, - "delayUnit": "ms", - "coilsBufferSize": 10000, - "holdingBufferSize": 10000, - "inputBufferSize": 10000, - "discreteBufferSize": 10000, - "showErrors": false, - "x": 240, - "y": 100, - "wires": [ - [], - [], - [], - [], - [] - ] + "id": "94d59eaf66811f1d", + "type": "modbus-server", + "z": "7ecaf10e98444c51", + "name": "", + "logEnabled": true, + "hostname": "127.0.0.1", + "serverPort": "5412", + "responseDelay": 100, + "delayUnit": "ms", + "coilsBufferSize": 10000, + "holdingBufferSize": 10000, + "inputBufferSize": 10000, + "discreteBufferSize": 10000, + "showErrors": false, + "x": 240, + "y": 100, + "wires": [ + [], + [], + [], + [], + [] + ] }, { - "id": "8921251df5afdb7b", - "type": "modbus-read", - "z": "7ecaf10e98444c51", - "name": "Modbus Read With IO", - "topic": "", - "showStatusActivities": false, - "logIOActivities": true, - "showErrors": false, - "unitid": "", - "dataType": "InputRegister", - "adr": "0", - "quantity": "20", - "rate": "200", - "rateUnit": "ms", - "delayOnStart": false, - "startDelayTime": "", - "server": "0de7212959503d3c", - "useIOFile": true, - "ioFile": "6822f8ed8da9824e", - "useIOForPayload": false, - "emptyMsgOnFail": false, - "x": 220, - "y": 180, - "wires": [ - [ - "bd82f396e8cde449" - ], - [] - ] + "id": "8921251df5afdb8b", + "type": "modbus-read", + "z": "7ecaf10e98444c51", + "name": "Modbus Read With IO", + "topic": "", + "showStatusActivities": false, + "logIOActivities": true, + "showErrors": false, + "showWarnings": true, + "unitid": "", + "dataType": "InputRegister", + "adr": "0", + "quantity": "20", + "rate": "200", + "rateUnit": "ms", + "delayOnStart": false, + "startDelayTime": "", + "server": "0de7212959503d3c", + "useIOFile": true, + "ioFile": "b0d101525a3ab7f5", + "useIOForPayload": false, + "emptyMsgOnFail": false, + "x": 280, + "y": 220, + "wires": [ + [ + "bd82f396e8cde449" + ], + [] + ] }, { - "id": "bd82f396e8cde449", - "type": "helper", - "z": "7ecaf10e98444c51", - "name": "", - "active": true, - "tosidebar": true, - "console": false, - "tostatus": false, - "complete": "payload", - "targetType": "msg", - "statusVal": "", - "statusType": "auto", - "x": 470, - "y": 160, - "wires": [] + "id": "bd82f396e8cde449", + "type": "helper", + "z": "7ecaf10e98444c51", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "payload", + "targetType": "msg", + "statusVal": "", + "statusType": "auto", + "x": 510, + "y": 220, + "wires": [] }, { - "id": "0de7212959503d3c", - "type": "modbus-client", - "z": "7ecaf10e98444c51", - "name": "ModbusServer", - "clienttype": "tcp", - "bufferCommands": true, - "stateLogEnabled": true, - "queueLogEnabled": false, - "failureLogEnabled": false, - "tcpHost": "127.0.0.1", - "tcpPort": "5412", - "tcpType": "DEFAULT", - "serialPort": "/dev/ttyUSB", - "serialType": "RTU-BUFFERD", - "serialBaudrate": "9600", - "serialDatabits": "8", - "serialStopbits": "1", - "serialParity": "none", - "serialConnectionDelay": "100", - "serialAsciiResponseStartDelimiter": "", - "unit_id": "1", - "commandDelay": "1", - "clientTimeout": "100", - "reconnectOnTimeout": false, - "reconnectTimeout": "200", - "parallelUnitIdsAllowed": true + "id": "0de7212959503d3c", + "type": "modbus-client", + "z": "7ecaf10e98444c51", + "name": "ModbusServer", + "clienttype": "tcp", + "bufferCommands": true, + "stateLogEnabled": true, + "queueLogEnabled": false, + "failureLogEnabled": false, + "tcpHost": "127.0.0.1", + "tcpPort": "5412", + "tcpType": "DEFAULT", + "serialPort": "/dev/ttyUSB", + "serialType": "RTU-BUFFERD", + "serialBaudrate": "9600", + "serialDatabits": "8", + "serialStopbits": "1", + "serialParity": "none", + "serialConnectionDelay": "100", + "serialAsciiResponseStartDelimiter": "", + "unit_id": "1", + "commandDelay": "1", + "clientTimeout": "100", + "reconnectOnTimeout": false, + "reconnectTimeout": "200", + "parallelUnitIdsAllowed": true, + "showErrors": false, + "showWarnings": true, + "showLogs": true }, { - "id": "6822f8ed8da9824e", - "type": "modbus-io-config", - "z": "7ecaf10e98444c51", - "name": "TestIOFile", - "path": "./test/resources/device.json", - "format": "utf8", - "addressOffset": "" + "id": "b0d101525a3ab7f5", + "type": "modbus-io-config", + "name": "TestIOFile", + "path": "./test/resources/device.json", + "format": "utf8", + "addressOffset": "" } - ] - - ), + ] + ), testShouldBeLoadedFlow: helperExtensions.cleanFlowPositionData([ { - id: 'ec42ecc63a604e72', - type: 'tab', - label: 'Should Be Loaded', - disabled: false, - info: '', - env: [] + "id": "ec42ecc63a604e72", + "type": "tab", + "label": "Should Be Loaded", + "disabled": false, + "info": "", + "env": [] }, { - id: 'b0fefd31.802188', - type: 'modbus-read', - z: 'ec42ecc63a604e72', - name: '', - topic: '', - showStatusActivities: false, - logIOActivities: false, - showErrors: false, - unitid: '', - dataType: '', - adr: '', - quantity: '', - rate: '', - rateUnit: '', - delayOnStart: false, - startDelayTime: '', - server: '', - useIOFile: true, - ioFile: '2f5a90d.bcaa1f', - useIOForPayload: false, - emptyMsgOnFail: false, - x: 350, - y: 240, - wires: [ + "id": "9c36e42ffe84d0ef", + "type": "modbus-read", + "z": "ec42ecc63a604e72", + "name": "", + "topic": "", + "showStatusActivities": false, + "logIOActivities": false, + "showErrors": false, + "showWarnings": true, + "unitid": "", + "dataType": "", + "adr": "", + "quantity": "", + "rate": "", + "rateUnit": "", + "delayOnStart": false, + "startDelayTime": "", + "server": "", + "useIOFile": true, + "ioFile": "181cab926ad54b55", + "useIOForPayload": false, + "emptyMsgOnFail": false, + "x": 450, + "y": 160, + "wires": [ [], [] ] }, { - id: '2f5a90d.bcaa1f', - type: 'modbus-io-config', - name: 'ModbusIOConfig', - path: 'testpath', - format: 'utf8', - addressOffset: '' + "id": "181cab926ad54b55", + "type": "modbus-io-config", + "name": "ModbusIOTest", + "path": "./test/resources/device.json", + "format": "utf8", + "addressOffset": "" } ]), @@ -241,7 +244,7 @@ module.exports = { id: '2f5a90d.bcaa1f', type: 'modbus-io-config', name: 'ModbusIOConfig', - path: 'testpath', + path: './test/resources/device.json', format: 'utf8', addressOffset: '' } diff --git a/test/units/flows/modbus-response-filter-flows.js b/test/units/flows/modbus-response-filter-flows.js index 47b4807f..ae8d7a8d 100644 --- a/test/units/flows/modbus-response-filter-flows.js +++ b/test/units/flows/modbus-response-filter-flows.js @@ -492,7 +492,7 @@ module.exports = { id: '7417947e.da6c3c', type: 'modbus-io-config', name: 'C3FactorySet', - path: './test/units/resources/device.json', + path: './test/resources/device.json', format: 'utf8', addressOffset: '' } diff --git a/test/units/modbus-flex-getter-test.js b/test/units/modbus-flex-getter-test.js index 5bc45fb9..bc5f6d01 100644 --- a/test/units/modbus-flex-getter-test.js +++ b/test/units/modbus-flex-getter-test.js @@ -56,8 +56,6 @@ describe('Flex Getter node Testing', function () { modbusFlexGetter.should.have.property('name', 'modbusFlexGetter') done() - }, function () { - helper.log('function callback') }) }) @@ -79,8 +77,6 @@ describe('Flex Getter node Testing', function () { modbusFlexGetter.should.have.property('name', 'modbusFlexGetter') done() - }, function () { - helper.log('function callback') }) }) }) @@ -102,8 +98,6 @@ describe('Flex Getter node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) }) @@ -124,8 +118,6 @@ describe('Flex Getter node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) }) @@ -150,8 +142,6 @@ describe('Flex Getter node Testing', function () { setTimeout(function () { modbusGetter.receive({ payload: '{ "fc": 1, "unitid": 1,"address": 0, "quantity": 4 }' }) }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -169,8 +159,6 @@ describe('Flex Getter node Testing', function () { modbusGetter.receive({ payload: '{ "value": "true", "fc": 5, "unitid": 1,"address": 0, "quantity": 1 }' }) done() }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -188,8 +176,6 @@ describe('Flex Getter node Testing', function () { modbusGetter.receive({ payload: '{ "fc": 1, "unitid": 1,"address": -1, "quantity": 1 }' }) done() }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -207,8 +193,6 @@ describe('Flex Getter node Testing', function () { modbusGetter.receive({ payload: '{ "fc": 1, "unitid": 1,"address": 1, "quantity": -1 }' }) done() }, 800) - }, function () { - helper.log('function callback') }) }) }) diff --git a/test/units/modbus-flex-sequencer-test.js b/test/units/modbus-flex-sequencer-test.js index cfdfe30e..bfc8ce7b 100644 --- a/test/units/modbus-flex-sequencer-test.js +++ b/test/units/modbus-flex-sequencer-test.js @@ -73,8 +73,6 @@ describe('Flex Sequencer node Testing', function () { modbusFlexSequencer.should.have.property('name', 'modbusFlexSequencer') done() - }, function () { - helper.log('function callback') }) }) diff --git a/test/units/modbus-flex-write-test.js b/test/units/modbus-flex-write-test.js index bc380563..980cd1a6 100644 --- a/test/units/modbus-flex-write-test.js +++ b/test/units/modbus-flex-write-test.js @@ -54,8 +54,6 @@ describe('Flex Write node Testing', function () { const modbusFlexWrite = helper.getNode('c02b6d1.d419c1') modbusFlexWrite.should.have.property('name', 'modbusFlexWrite') done() - }, function () { - helper.log('function callback') }) }) @@ -64,8 +62,6 @@ describe('Flex Write node Testing', function () { const modbusFlexWrite = helper.getNode('c02b6d1.d419c1') modbusFlexWrite.should.have.property('name', 'modbusFlexWrite') done() - }, function () { - helper.log('function callback') }) }) @@ -75,8 +71,6 @@ describe('Flex Write node Testing', function () { h1.on('input', function () { done() }) - }, function () { - helper.log('function callback') }) }) @@ -97,8 +91,6 @@ describe('Flex Write node Testing', function () { flexWriter.receive({}) }, 800) setTimeout(done, 1200) - }, function () { - helper.log('function callback') }) }) }) @@ -120,8 +112,6 @@ describe('Flex Write node Testing', function () { flexWriter.receive({ payload: '{ "value": true, "fc": 1, "unitid": 1,"address": 0, "quantity": 1 }' }) }, 800) setTimeout(done, 1200) - }, function () { - helper.log('function callback') }) }) }) @@ -143,8 +133,6 @@ describe('Flex Write node Testing', function () { flexWriter.receive({ payload: '{ "value": true, "fc": 5, "unitid": 1,"address": -1, "quantity": 1 }' }) }, 800) setTimeout(done, 1200) - }, function () { - helper.log('function callback') }) }) }) @@ -166,8 +154,6 @@ describe('Flex Write node Testing', function () { flexWriter.receive({ payload: '{ "value": true, "fc": 5, "unitid": 1,"address": 1, "quantity": -1 }' }) }, 800) setTimeout(done, 1200) - }, function () { - helper.log('function callback') }) }) }) @@ -190,8 +176,6 @@ describe('Flex Write node Testing', function () { setTimeout(function () { flexWriter.receive({ payload: '{ "value": true, "fc": 5, "unitid": 1,"address": 0, "quantity": 1 }' }) }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -214,8 +198,6 @@ describe('Flex Write node Testing', function () { setTimeout(function () { flexWriter.receive({ payload: '{ "value": [0,1,0,1], "fc": 5, "unitid": 1,"address": 0, "quantity": 4 }' }) }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -238,8 +220,6 @@ describe('Flex Write node Testing', function () { setTimeout(function () { flexWriter.receive({ payload: { value: 'true', fc: 5, unitid: 1, address: 0, quantity: 1 } }) }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -262,8 +242,6 @@ describe('Flex Write node Testing', function () { setTimeout(function () { flexWriter.receive({ payload: { value: 'false', fc: 5, unitid: 1, address: 0, quantity: 1 } }) }, 800) - }, function () { - helper.log('function callback') }) }) }) diff --git a/test/units/modbus-getter-test.js b/test/units/modbus-getter-test.js index 1be070c1..4909fe40 100644 --- a/test/units/modbus-getter-test.js +++ b/test/units/modbus-getter-test.js @@ -55,8 +55,6 @@ describe('Getter node Unit Testing', function () { modbusGetter.should.have.property('name', 'modbusGetter') done() - }, function () { - helper.log('function callback') }) }) @@ -78,8 +76,6 @@ describe('Getter node Unit Testing', function () { modbusGetter.should.have.property('name', 'modbusGetter') done() - }, function () { - helper.log('function callback') }) }) }) @@ -100,8 +96,6 @@ describe('Getter node Unit Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) }) @@ -123,8 +117,6 @@ describe('Getter node Unit Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) }) @@ -145,8 +137,6 @@ describe('Getter node Unit Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) }) @@ -164,8 +154,6 @@ describe('Getter node Unit Testing', function () { modbusGetter.receive({ payload: '{ "value": "true", "fc": 5, "unitid": 1,"address": 0, "quantity": 4 }' }) done() }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -183,8 +171,6 @@ describe('Getter node Unit Testing', function () { modbusGetter.receive({ payload: '{ "fc": 1, "unitid": 1,"address": -1, "quantity": 4 }' }) done() }, 800) - }, function () { - helper.log('function callback') }) }) }) @@ -202,8 +188,6 @@ describe('Getter node Unit Testing', function () { modbusGetter.receive({ payload: '{ "fc": 1, "unitid": 1,"address": 0, "quantity": -1 }' }) done() }, 800) - }, function () { - helper.log('function callback') }) }) }) diff --git a/test/units/modbus-io-config-test.js b/test/units/modbus-io-config-test.js index 574e047f..525346e4 100644 --- a/test/units/modbus-io-config-test.js +++ b/test/units/modbus-io-config-test.js @@ -10,21 +10,23 @@ 'use strict' -const nodeUnderTest = require('../../src/modbus-io-config.js') -const readNode = require('../../src/modbus-read.js') +const nodeUnderTest = require('../../src/modbus-io-config') +const readNode = require('../../src/modbus-read') const catchNode = require('@node-red/nodes/core/common/25-catch') const injectNode = require('@node-red/nodes/core/common/20-inject') const functionNode = require('@node-red/nodes/core/function/10-function') const clientNode = require('../../src/modbus-client') const serverNode = require('../../src/modbus-server') +const fs = require('fs') + const helper = require('node-red-node-test-helper') helper.init(require.resolve('node-red')) const testIoConfigNodes = [catchNode, injectNode, functionNode, clientNode, serverNode, nodeUnderTest, readNode] const testFlows = require('./flows/modbus-io-config-flows') -const mBasics = require('../../src/modbus-basics') +const { getPort } = require('../helper/test-helper-extensions') describe('IO Config node Testing', function () { before(function (done) { @@ -48,50 +50,90 @@ describe('IO Config node Testing', function () { }) describe('Node', function () { - // it('should reload the file when it changes', () => { - // helper.load(testIoConfigNodes, testFlows.testReadWithClientIoFlow, function () { - // const modbusIOConfigNode = helper.getNode('6822f8ed8da9824e') - // node.watcher.emit(modbusIOConfigNode.path, { mtime: 123 }, { mtime: 456 }); - // done() - // }) - // }) + it('should reload the file when it changes line', (done) => { + const flow = Array.from(testFlows.testReadWithClientIoFlow) - it('should be loaded', function (done) { - helper.load(testIoConfigNodes, testFlows.testShouldBeLoadedFlow, function () { - const modbusIOConfigNode = helper.getNode('2f5a90d.bcaa1f') - modbusIOConfigNode.should.have.property('name', 'ModbusIOConfig') - done() + getPort().then((port) => { + flow[1].serverPort = port + flow[4].tcpPort = port + + helper.load(testIoConfigNodes, flow, function () { + const modbusIOConfigNode = helper.getNode('b0d101525a3ab7f5') + let counter = 0 + modbusIOConfigNode.lineReader.on('line', () => { + counter++ + if (counter === 2) { + done() + } + }) + }) }) }) - it('should be state queueing - ready to send', function (done) { - helper.load(testIoConfigNodes, testFlows.testShouldBeReadyToSendFlow, function () { - const modbusClientNode = helper.getNode('1b49af22a0d089c9') - setTimeout(() => { - mBasics.setNodeStatusTo('queueing', modbusClientNode) - const isReady = modbusClientNode.isReadyToSend(modbusClientNode) - isReady.should.be.false() - done() - }, 1500) + it('should reload the file when it changes end', (done) => { + const flow = Array.from(testFlows.testReadWithClientIoFlow) + + getPort().then((port) => { + flow[1].serverPort = port + flow[4].tcpPort = port + + helper.load(testIoConfigNodes, flow, function () { + const modbusIOConfigNode = helper.getNode('b0d101525a3ab7f5') + let counter = 0 + + modbusIOConfigNode.on('updatedConfig', (data) => { + counter++ + if (data && counter === 1) { + done() + } + }) + }) }) }) - it('should be not state queueing - not ready to send', function (done) { - helper.load(testIoConfigNodes, testFlows.testShouldBeReadyToSendFlow, function () { - const modbusClientNode = helper.getNode('1b49af22a0d089c9') - setTimeout(() => { - mBasics.setNodeStatusTo('stopped', modbusClientNode) - const isReady = modbusClientNode.isReadyToSend(modbusClientNode) - isReady.should.be.false() - done() - }, 1500) + it('should watch the file when it changes', (done) => { + const flow = Array.from(testFlows.testReadWithClientIoFlow) + + getPort().then((port) => { + flow[1].serverPort = port + flow[4].tcpPort = port + + helper.load(testIoConfigNodes, flow, function () { + const modbusIOConfigNode = helper.getNode('b0d101525a3ab7f5') + let counter = 0 + + modbusIOConfigNode.on('updatedConfig', (data) => { + counter++ + if (data && counter === 2) { // first from the load and second from watch + done() + } + }) + + setTimeout(() => { + const rawdata = fs.readFileSync('./test/resources/deviceCopy.json') + fs.writeFileSync('./test/resources/device.json', rawdata) + + setTimeout(() => { + const rawdata = fs.readFileSync('./test/resources/deviceCopy.json') + fs.writeFileSync('./test/resources/device.json', rawdata) + }, 1000) + }, 1000) + }) + }) + }) + + it('should be loaded', function (done) { + helper.load(testIoConfigNodes, testFlows.testShouldBeLoadedFlow, function () { + const modbusIOConfigNode = helper.getNode('181cab926ad54b55') + modbusIOConfigNode.should.have.property('name', 'ModbusIOTest') + done() }) }) }) describe('post', function () { it('should fail for invalid node', function (done) { - helper.load(testIoConfigNodes, testFlows.testShouldBeReadyToSendFlow, function () { + helper.load(testIoConfigNodes, [], function () { helper.request().post('/modbus-io-config/invalid').expect(404).end(done) }) }) diff --git a/test/units/modbus-queue-info-test.js b/test/units/modbus-queue-info-test.js index 748b9424..43d816d6 100644 --- a/test/units/modbus-queue-info-test.js +++ b/test/units/modbus-queue-info-test.js @@ -190,8 +190,6 @@ describe('Queue Info node Testing', function () { modbusQueueInfo.should.have.property('name', 'modbusQueueInfo') done() - }, function () { - helper.log('function callback') }) }) // TO BE FIXED @@ -327,8 +325,6 @@ describe('Queue Info node Testing', function () { }) const queueNode = helper.getNode('5fffb0bc.0b8a5') queueNode.receive({ payload: { resetQueue: true } }) - }, function () { - helper.log('function callback') }) }) @@ -344,8 +340,6 @@ describe('Queue Info node Testing', function () { }) const queueNode = helper.getNode('5fffb0bc.0b8a5') queueNode.receive({ payload: '', resetQueue: true }) - }, function () { - helper.log('function callback') }) }) @@ -357,8 +351,6 @@ describe('Queue Info node Testing', function () { }) const queueNode = helper.getNode('5fffb0bc.0b8a5') queueNode.receive({ payload: { resetQueue: true } }) - }, function () { - helper.log('function callback') }) }) diff --git a/test/units/modbus-read-test.js b/test/units/modbus-read-test.js index 47a3a847..5d75f856 100644 --- a/test/units/modbus-read-test.js +++ b/test/units/modbus-read-test.js @@ -50,8 +50,6 @@ describe('Read node Testing', function () { const modbusRead = helper.getNode('8ecaae3e.4b8928') modbusRead.should.have.property('name', 'modbusRead') done() - }, function () { - helper.log('function callback') }) }) @@ -67,8 +65,6 @@ describe('Read node Testing', function () { modbusRead.should.have.property('name', 'modbusRead') done() - }, function () { - helper.log('function callback') }) }) @@ -82,8 +78,6 @@ describe('Read node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -97,8 +91,6 @@ describe('Read node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -112,8 +104,6 @@ describe('Read node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -127,8 +117,6 @@ describe('Read node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -235,8 +223,6 @@ describe('Read node Testing', function () { it('should inject on valid node', function (done) { helper.load([clientNode, serverNode, readNode], testFlows.testReadWithClientFlow, function () { helper.request().post('/modbus/read/inject/09846c74de630616').expect(200).end(done) - }, function () { - helper.log('function callback') }) }) }) diff --git a/test/units/modbus-response-filter-test.js b/test/units/modbus-response-filter-test.js index 233acdeb..93ed46f4 100644 --- a/test/units/modbus-response-filter-test.js +++ b/test/units/modbus-response-filter-test.js @@ -148,8 +148,12 @@ describe('Response Filter node Testing', function () { modbusNode.should.have.property('filter', 'bOperationActive') const h1 = helper.getNode('h1') + let counter = 0 h1.on('input', function () { - done() + counter++ + if (counter === 1) { + done() + } }) }) }) @@ -169,7 +173,7 @@ describe('Response Filter node Testing', function () { describe('post', function () { it('should fail for invalid node', function (done) { - helper.load(testResponseFilterNodes, testFlows.testWorkWithFlexGetterFlow, function () { + helper.load(testResponseFilterNodes, [], function () { helper.request().post('/modbus-response-filter/invalid').expect(404).end(done) }) }) diff --git a/test/units/modbus-server-test.js b/test/units/modbus-server-test.js index 42f8f6d7..affafc92 100644 --- a/test/units/modbus-server-test.js +++ b/test/units/modbus-server-test.js @@ -134,8 +134,6 @@ describe('Server node Testing', function () { modbusServer.should.have.property('name', 'modbusServer') done() - }, function () { - helper.log('function callback') }) }) @@ -145,8 +143,6 @@ describe('Server node Testing', function () { modbusServer.should.have.property('name', 'modbusServer') done() - }, function () { - helper.log('function callback') }) }) @@ -156,8 +152,6 @@ describe('Server node Testing', function () { h1.on('input', function () { done() }) - }, function () { - helper.log('function callback') }) }) diff --git a/test/units/modbus-write-test.js b/test/units/modbus-write-test.js index 8476deb4..1c3e7823 100644 --- a/test/units/modbus-write-test.js +++ b/test/units/modbus-write-test.js @@ -60,8 +60,6 @@ describe('Write node Testing', function () { modbusWrite.should.have.property('name', 'modbusWrite') done() - }, function () { - helper.log('function callback') }) }) @@ -74,8 +72,6 @@ describe('Write node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -91,8 +87,6 @@ describe('Write node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -110,8 +104,6 @@ describe('Write node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -129,8 +121,6 @@ describe('Write node Testing', function () { done() } }) - }, function () { - helper.log('function callback') }) }) @@ -148,8 +138,6 @@ describe('Write node Testing', function () { setTimeout(function () { modbusWrite.receive({ payload: '{ "value": [0,1,0,1], "fc": 5, "unitid": 1,"address": 0, "quantity": 4 }' }) }, 800) - }, function () { - helper.log('function callback') }) }) diff --git a/yarn.lock b/yarn.lock index 91a929f8..11e0851d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9719,9 +9719,9 @@ type-fest@^0.8.0, type-fest@^0.8.1: integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== type-fest@^4.6.0, type-fest@^4.7.1: - version "4.20.0" - resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.20.0.tgz#019becf5a97cd58eee93f592f0961859a74482a7" - integrity sha512-MBh+PHUHHisjXf4tlx0CFWoMdjx8zCMLJHOjnV1prABYZFHqtFOyauCIK2/7w4oIfwkF8iNhLtnJEfVY2vn3iw== + version "4.20.1" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.20.1.tgz#d97bb1e923bf524e5b4b43421d586760fb2ee8be" + integrity sha512-R6wDsVsoS9xYOpy8vgeBlqpdOyzJ12HNfQhC/aAKWM3YoCV9TtunJzh/QpkMgeDhkoynDcw5f1y+qF9yc/HHyg== type-is@^1.6.4, type-is@~1.6.18: version "1.6.18" @@ -10318,9 +10318,9 @@ ws@7.5.6: integrity sha512-6GLgCqo2cy2A2rjCNFlxQS6ZljG/coZfZXclldI8FB/1G3CCI36Zd8xy2HrFVACi8tfk5XrgLQEk+P0Tnz9UcA== ws@^7.5.5: - version "7.5.9" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" - integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== + version "7.5.10" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9" + integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ== xdg-basedir@^4.0.0: version "4.0.0"