Skip to content

Commit

Permalink
Upgrade to Node 20
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
microbit-matt-hillsdon committed Sep 21, 2023
1 parent 7269d44 commit ae8a5f5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 1 addition & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 16 additions & 31 deletions src/device/webusb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};
});

Expand Down Expand Up @@ -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.
});

0 comments on commit ae8a5f5

Please sign in to comment.