From 84bac2b8d8020b8b6bb79e17295447f4c99af4c6 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sat, 21 May 2022 14:37:39 +0800 Subject: [PATCH] Add compatibility tests (#12527) * Add tests gh action * Fix zigbee_ota_override_index_location * Fix Shouldnt crash when it cannot save state test * Add node17 * Update tests.yml * Drop old versions * Move to ci.yml * Update controller.test.js * Fix linebraks on windows * Ignore windows and node 17 * Fail on error * Add comment * Mark node 18 as supported Co-authored-by: nurikk --- .eslintrc.js | 1 + .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ package.json | 2 +- test/controller.test.js | 2 +- test/otaUpdate.test.js | 5 ++++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ccfd9eb77..083b59576 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,6 +15,7 @@ module.exports = { 'indent': ['error', 4], 'max-len': ['error', {'code': 120}], 'no-prototype-builtins': 'off', + 'linebreak-style': ['error', (process.platform === 'win32' ? 'windows' : 'unix')], // https://stackoverflow.com/q/39114446/2771889 }, 'plugins': [ 'jest', diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9040e993..26b69586f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,37 @@ name: CI on: [push, pull_request] jobs: + tests: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + node: [14, 16, 17, 18] + exclude: + - os: windows-latest # https://github.com/serialport/node-serialport/issues/2344 + node: 17 + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + registry-url: https://registry.npmjs.org/ + + - name: Restore node_modules cache + id: cache-node-modules + uses: actions/cache@v3 + with: + path: node_modules + key: ${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('npm-shrinkwrap.json') }} + - name: Install dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm ci + - name: Lint + run: npm run eslint + - name: Build + run: npm run build + - name: Test + run: npm run test-with-coverage ci: runs-on: ubuntu-latest steps: diff --git a/package.json b/package.json index 1fd93671e..2be7d5366 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "git+https://github.com/Koenkk/zigbee2mqtt.git" }, "engines": { - "node": "^10 || ^12 || ^14 || ^15 || ^16 || ^17" + "node": "^10 || ^12 || ^14 || ^15 || ^16 || ^17 || ^18" }, "keywords": [ "xiaomi", diff --git a/test/controller.test.js b/test/controller.test.js index b5a075b09..ec7dc54c6 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -569,7 +569,7 @@ describe('Controller', () => { logger.error.mockClear(); controller.state.file = "/"; await controller.state.save(); - expect(logger.error).toHaveBeenCalledWith(`Failed to write state to '/' (EISDIR: illegal operation on a directory, open '/')`); + expect(logger.error).toHaveBeenCalledWith(expect.stringMatching(/Failed to write state to \'\/\'/)); }); it('Publish should not cache when set', async () => { diff --git a/test/otaUpdate.test.js b/test/otaUpdate.test.js index 6dfa104d5..59fb43c34 100644 --- a/test/otaUpdate.test.js +++ b/test/otaUpdate.test.js @@ -1,3 +1,5 @@ +const path = require('path'); + const data = require('./stub/data'); const logger = require('./stub/logger'); const zigbeeHerdsman = require('./stub/zigbeeHerdsman'); @@ -11,6 +13,7 @@ const zigbeeOTA = require('zigbee-herdsman-converters/lib/ota/zigbeeOTA'); const spyUseIndexOverride = jest.spyOn(zigbeeOTA, 'useIndexOverride'); + describe('OTA update', () => { let controller; @@ -468,7 +471,7 @@ describe('OTA update', () => { it('Set zigbee_ota_override_index_location', async () => { settings.set(['ota', 'zigbee_ota_override_index_location'], 'local.index.json'); await resetExtension(); - expect(spyUseIndexOverride).toHaveBeenCalledWith(data.mockDir + '/local.index.json'); + expect(spyUseIndexOverride).toHaveBeenCalledWith(path.join(data.mockDir, 'local.index.json')); spyUseIndexOverride.mockClear(); settings.set(['ota', 'zigbee_ota_override_index_location'], 'http://my.site/index.json');