diff --git a/.github/workflows/lights-test.yml b/.github/workflows/lights-test.yml index 817bfeee..aac16ec1 100644 --- a/.github/workflows/lights-test.yml +++ b/.github/workflows/lights-test.yml @@ -14,12 +14,13 @@ jobs: - name: Run containers run: | sudo chown -R 1000:1000 data/nodered - docker compose --env-file example.env up --build --force-recreate -d + docker compose --env-file example.env up --build --force-recreate -d automations features broker - name: Setup node uses: actions/setup-node@v3.5.1 with: - node-version: 14 + node-version: 22 + node-version-file: docker/test/.nvmrc - name: Run tests run: | diff --git a/docker/test/.nvmrc b/docker/test/.nvmrc new file mode 100644 index 00000000..2bd5a0a9 --- /dev/null +++ b/docker/test/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/docker/test/index.js b/docker/test/index.js index ce69d325..186d70a9 100644 --- a/docker/test/index.js +++ b/docker/test/index.js @@ -6,7 +6,6 @@ const timer = setTimeout(() => { console.error('Timeout!') process.exit(1) }, 2000) -let interval = null const publish = (topic, payload) => { console.log(`> [${topic}]: ${JSON.stringify(payload)}`) @@ -15,39 +14,39 @@ const publish = (topic, payload) => { client.on('connect', () => { console.log('connected, sending...') - client.subscribe('#', async (err) => { + client.subscribe(['#'], async (err) => { if (err) { console.log('Error sending', err) process.exit(1) } - let inputs = 0 - setInterval(() => { - inputs = inputs === 0 ? 1 << 27 : 0 - publish('/modbus/dry-switches/mbsl32di2/reading', JSON.stringify({ - "inputs": inputs, - "_tz": Date.now(), - "_ms": 7, - "_addr": 32, - "_type": "mbsl32di", - "device": "mbsl32di2" - })) - }, 100) + await publish('/modbus/dry-switches/mbsl32di2/reading', { + "inputs": 0, + "_tz": Date.now(), + "_ms": 7, + "_addr": 32, + "_type": "mbsl32di", + "device": "mbsl32di2" + }) + await publish('/modbus/dry-switches/mbsl32di2/reading', { + "inputs": 1 << 27, + "_tz": Date.now(), + "_ms": 7, + "_addr": 32, + "_type": "mbsl32di", + "device": "mbsl32di2" + }) }) }) client.on('message', (topic, message) => { console.log(`< [${topic}]: ${message}`) // message is Buffer - switch (topic) { - case '/modbus/dry-switches/relays00-15/write': { - const msg = JSON.parse(message) - if (msg.out8 === true) { - clearTimeout(timer) - clearInterval(interval) - client.end() - } + if (topic === '/modbus/dry-switches/relays00-15/write') { + const msg = JSON.parse(message) + if (msg.out8 === true) { + clearTimeout(timer) + client.end() } - break } })