From 68750fade096118cfa88c22aa9380826b6d110eb Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 2 Mar 2020 19:11:43 +0100 Subject: [PATCH] Fix tests on node 12. https://github.com/Koenkk/zigbee2mqtt/issues/3031 --- azure-pipelines.yaml | 2 +- test/entityPublish.test.js | 2 -- test/group.test.js | 8 ++++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml index 5b68f9167..8833c42b6 100644 --- a/azure-pipelines.yaml +++ b/azure-pipelines.yaml @@ -14,7 +14,7 @@ steps: # Prepare - task: NodeTool@0 inputs: - versionSpec: '10.x' + versionSpec: '12.x' displayName: 'Install Node.js' - bash: npm ci displayName: 'Install dependencies' diff --git a/test/entityPublish.test.js b/test/entityPublish.test.js index 686f34088..a52ef2dd0 100644 --- a/test/entityPublish.test.js +++ b/test/entityPublish.test.js @@ -5,7 +5,6 @@ const MQTT = require('./stub/mqtt'); const settings = require('../lib/util/settings'); const Controller = require('../lib/controller'); const flushPromises = () => new Promise(setImmediate); -const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const mocksClear = [MQTT.publish, logger.warn, logger.debug]; @@ -30,7 +29,6 @@ describe('Entity publish', () => { controller = new Controller(); await controller.start(); await flushPromises(); - await wait(50); }); beforeEach(async () => { diff --git a/test/group.test.js b/test/group.test.js index 65a491df1..744d12c4e 100644 --- a/test/group.test.js +++ b/test/group.test.js @@ -14,6 +14,7 @@ describe('Groups', () => { let controller; beforeEach(() => { + data.writeEmptyState(); controller = new Controller(); Object.values(zigbeeHerdsman.groups).forEach((g) => g.members = []); data.writeDefaultConfiguration(); @@ -306,7 +307,6 @@ describe('Groups', () => { await flushPromises(); MQTT.publish.mockClear(); - controller.state.state = {}; const payload = {data: {onOff: 1}, cluster: 'genOnOff', device, endpoint, type: 'attributeReport', linkquality: 10}; await zigbeeHerdsman.events.message(payload); await flushPromises(); @@ -410,8 +410,8 @@ describe('Groups', () => { await flushPromises(); expect(MQTT.publish).toHaveBeenCalledTimes(3); expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb_color", '{"state":"OFF"}', {"retain": false, qos: 0}, expect.any(Function)); - expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb", '{"state":"OFF","brightness":50,"color_temp":370,"linkquality":99}', {"retain": true, qos: 0}, expect.any(Function)); - expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/group_1", '{"state":"OFF","brightness":50,"color_temp":370}', {"retain": false, qos: 0}, expect.any(Function)); + expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb", '{"state":"OFF"}', {"retain": true, qos: 0}, expect.any(Function)); + expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/group_1", '{"state":"OFF"}', {"retain": false, qos: 0}, expect.any(Function)); }); it('Should publish state change off even when missing current state', async () => { @@ -440,4 +440,4 @@ describe('Groups', () => { expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb_color", '{"state":"OFF"}', {"retain": false, qos: 0}, expect.any(Function)); expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/group_1", '{"state":"OFF"}', {"retain": false, qos: 0}, expect.any(Function)); }); -}); +}); \ No newline at end of file