From ae8a5f50d00ed073b085907de7f860ebd75a35a1 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Thu, 21 Sep 2023 11:50:50 +0100 Subject: [PATCH] Upgrade to Node 20 Drop webusb dep that's only used for some test we largely didn't complete. Replace the working test with a mock as its use of the webusb dep wasn't meaningful. --- .github/workflows/build.yml | 2 +- package-lock.json | 98 +------------------------------------ package.json | 3 +- src/device/webusb.test.ts | 47 ++++++------------ 4 files changed, 19 insertions(+), 131 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 70ad78cfc..8e537617b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: - name: Configure node uses: actions/setup-node@v3 with: - node-version: 16.x + node-version: 20.x cache: "npm" registry-url: "https://npm.pkg.github.com" - run: npm ci diff --git a/package-lock.json b/package-lock.json index c0d33676b..3993ac696 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,8 +71,7 @@ "puppeteer": "^13.4.0", "react-scripts": "5.0.0", "source-map-explorer": "^2.5.2", - "typescript": "^4.4.2", - "webusb": "^2.2.0" + "typescript": "^4.4.2" }, "engines": { "node": ">=16.0", @@ -17187,12 +17186,6 @@ "tslib": "^2.0.3" } }, - "node_modules/node-addon-api": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.2.0.tgz", - "integrity": "sha512-eazsqzwG2lskuzBqCGPi7Ac2UgOoMz8JVOXVhTvvPDYhthvNpefx8jWD8Np7Gv+2Sz0FlPWZk0nJV0z598Wn8Q==", - "dev": true - }, "node_modules/node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -17244,17 +17237,6 @@ "node": ">= 6.13.0" } }, - "node_modules/node-gyp-build": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.3.0.tgz", - "integrity": "sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q==", - "dev": true, - "bin": { - "node-gyp-build": "bin.js", - "node-gyp-build-optional": "optional.js", - "node-gyp-build-test": "build-test.js" - } - }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -22307,20 +22289,6 @@ "punycode": "^2.1.0" } }, - "node_modules/usb": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/usb/-/usb-1.9.1.tgz", - "integrity": "sha512-T6DZbJAFNcxhY1FzaYdXhV2oqoRlvLhtSSmnbFAqyCxahUkc+g0BPZVXv7hIeQQxDCAQnr4Ia8bfOk1JlzNzzw==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "node-addon-api": "^4.2.0", - "node-gyp-build": "^4.3.0" - }, - "engines": { - "node": ">=10.16.0" - } - }, "node_modules/use-asset": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/use-asset/-/use-asset-1.0.4.tgz", @@ -22949,28 +22917,6 @@ "node": ">=0.8.0" } }, - "node_modules/webusb": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/webusb/-/webusb-2.2.0.tgz", - "integrity": "sha512-EP6JOFIqR4vLoDWwtMROs94Sl/sZlmX1WApK9O8/rBMBEiYTrDlgQrfUQ4CW5o+GSxfbA+MpDRgGbEBa5q0ECw==", - "deprecated": "This package is deprecated, please use the WebUSB API in the 'usb' package instead", - "dev": true, - "dependencies": { - "@types/node": "^8.0.54", - "@types/usb": "^1.5.1", - "@types/w3c-web-usb": "^1.0.4", - "usb": "^1.6.0" - }, - "engines": { - "node": ">=8.14.0" - } - }, - "node_modules/webusb/node_modules/@types/node": { - "version": "8.10.66", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.66.tgz", - "integrity": "sha512-tktOkFUA4kXx2hhhrB8bIFb5TbwzS4uOhKEmwiD+NoiL0qtP2OQ9mFldbgD4dV1djrlBYP6eBuQZiWjuHUpqFw==", - "dev": true - }, "node_modules/whatwg-encoding": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz", @@ -36737,12 +36683,6 @@ "tslib": "^2.0.3" } }, - "node-addon-api": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.2.0.tgz", - "integrity": "sha512-eazsqzwG2lskuzBqCGPi7Ac2UgOoMz8JVOXVhTvvPDYhthvNpefx8jWD8Np7Gv+2Sz0FlPWZk0nJV0z598Wn8Q==", - "dev": true - }, "node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -36782,12 +36722,6 @@ "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", "dev": true }, - "node-gyp-build": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.3.0.tgz", - "integrity": "sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q==", - "dev": true - }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -40429,16 +40363,6 @@ "punycode": "^2.1.0" } }, - "usb": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/usb/-/usb-1.9.1.tgz", - "integrity": "sha512-T6DZbJAFNcxhY1FzaYdXhV2oqoRlvLhtSSmnbFAqyCxahUkc+g0BPZVXv7hIeQQxDCAQnr4Ia8bfOk1JlzNzzw==", - "dev": true, - "requires": { - "node-addon-api": "^4.2.0", - "node-gyp-build": "^4.3.0" - } - }, "use-asset": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/use-asset/-/use-asset-1.0.4.tgz", @@ -40909,26 +40833,6 @@ "integrity": "sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==", "dev": true }, - "webusb": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/webusb/-/webusb-2.2.0.tgz", - "integrity": "sha512-EP6JOFIqR4vLoDWwtMROs94Sl/sZlmX1WApK9O8/rBMBEiYTrDlgQrfUQ4CW5o+GSxfbA+MpDRgGbEBa5q0ECw==", - "dev": true, - "requires": { - "@types/node": "^8.0.54", - "@types/usb": "^1.5.1", - "@types/w3c-web-usb": "^1.0.4", - "usb": "^1.6.0" - }, - "dependencies": { - "@types/node": { - "version": "8.10.66", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.66.tgz", - "integrity": "sha512-tktOkFUA4kXx2hhhrB8bIFb5TbwzS4uOhKEmwiD+NoiL0qtP2OQ9mFldbgD4dV1djrlBYP6eBuQZiWjuHUpqFw==", - "dev": true - } - } - }, "whatwg-encoding": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz", diff --git a/package.json b/package.json index d1b8b5f3e..caa922314 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,7 @@ "puppeteer": "^13.4.0", "react-scripts": "5.0.0", "source-map-explorer": "^2.5.2", - "typescript": "^4.4.2", - "webusb": "^2.2.0" + "typescript": "^4.4.2" }, "engines": { "node": ">=16.0", diff --git a/src/device/webusb.test.ts b/src/device/webusb.test.ts index e32584628..6b69e519b 100644 --- a/src/device/webusb.test.ts +++ b/src/device/webusb.test.ts @@ -10,10 +10,16 @@ * with a tweak to Buffer. */ import { ConnectionStatus, EVENT_STATUS } from "./device"; -import { USB } from "webusb"; import { NullLogging } from "../deployment/default/logging"; import { MicrobitWebUSBConnection } from "./webusb"; +jest.mock("./dap-wrapper", () => ({ + DAPWrapper: class DapWrapper { + startSerial = jest.fn().mockReturnValue(Promise.resolve()); + reconnectAsync = jest.fn(); + }, +})); + const describeDeviceOnly = process.env.TEST_MODE_DEVICE ? describe : describe.skip; @@ -30,9 +36,17 @@ describe("MicrobitWebUSBConnection (WebUSB unsupported)", () => { describeDeviceOnly("MicrobitWebUSBConnection (WebUSB supported)", () => { beforeAll(() => { + const usb = { + addEventListener: jest.fn(), + removeEventListener: jest.fn(), + requestDevice() { + const device = {}; + return device; + }, + }; // Maybe we can move this to a custom jest environment? (global as any).navigator = { - usb: new USB({}), + usb, }; }); @@ -64,33 +78,4 @@ describeDeviceOnly("MicrobitWebUSBConnection (WebUSB supported)", () => { ConnectionStatus.NOT_CONNECTED, ]); }); - - it("flashes using partial flashing when possible", async () => { - // Flash MakeCode hex that outputs serial. - // Flash MicroPython hex that outputs serial. - // Flash another MicroPython hex, assert that we got a small number of progress events. - // I think we need to rejig the interface to get flash data before writing this. - }); - - it("connects to flash and stays connected afterwards", () => { - // Is this actually sensible? - }); - - it("fires a serial reset event when stopping serial", () => {}); - - it("reinstates serial after flashing", () => {}); - - it("serial echo test", async () => { - // Flash a hex that echos serial - // Use serialWrite to write serial data. - // Assert same content is received. - // Useful to test unicode? - }); - - it("notices disconnects and updates status", () => { - // Might need a mock-style tests for this. - }); - - // Is it feasible to test many of the error cases? - // I think we'd need to pass a mock DAPWrapper. });