-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split into CI & local integration tests + stub-data unit tests
- Loading branch information
Showing
5 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { expect } from "chai"; | ||
import { delay } from "@httptoolkit/util"; | ||
|
||
import { UsbmuxClient, getUsbmuxClient } from "../src/index"; | ||
|
||
describe("Usbmux-client integration tests", () => { | ||
|
||
let client: UsbmuxClient | undefined; | ||
|
||
afterEach(() => { | ||
client?.close(); | ||
client = undefined; | ||
}); | ||
|
||
if (process.env.CI) { | ||
it("can query the connected devices (seeing no results)", async () => { | ||
client = await getUsbmuxClient(); | ||
await delay(10); // Not clear this is necessary, but not unhelpful | ||
|
||
const devices = client.getDevices(); | ||
|
||
// Tests assume no devices in CI but this at least confirms we can connect | ||
// to Usbmux successfully. | ||
expect(devices).to.deep.equal({}); | ||
}); | ||
} else { | ||
it("can detect the connected device", async () => { | ||
client = await getUsbmuxClient(); | ||
await delay(10); // Not clear this is necessary, but not unhelpful | ||
|
||
const devices = client.getDevices(); | ||
|
||
// Local integratiion testing assumes you'll test with a real device | ||
expect(devices).to.be.an('object'); | ||
expect(Object.keys(devices).length).to.be.greaterThan(0, | ||
"Local integration testing assumes at least one iOS device connected" | ||
); | ||
|
||
const deviceId = Object.keys(devices)[0]; | ||
expect(devices[deviceId]).to.be.an('object'); | ||
expect(devices[deviceId].DeviceID).to.equal(parseInt(deviceId)); | ||
expect(devices[deviceId].ConnectionType).to.equal('USB'); | ||
expect(devices[deviceId].SerialNumber).to.be.a('string'); | ||
expect((devices[deviceId].SerialNumber as any).length).to.equal(40); | ||
}); | ||
} | ||
|
||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as net from 'net'; | ||
|
||
import { expect } from 'chai'; | ||
import { makeDestroyable } from "destroyable-server"; | ||
|
||
import { UsbmuxClient, getUsbmuxClient } from "../src/index"; | ||
import { delay } from '@httptoolkit/util'; | ||
|
||
// Various Base64 encoded messages we expect or use a test data: | ||
const MESSAGES = { | ||
LISTEN_REQUEST: Buffer.from("hwEAAAAAAAAIAAAAAQAAADw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04Ij8+CjwhRE9DVFlQRSBwbGlzdCBQVUJMSUMgIi0vL0FwcGxlLy9EVEQgUExJU1QgMS4wLy9FTiIgImh0dHA6Ly93d3cuYXBwbGUuY29tL0RURHMvUHJvcGVydHlMaXN0LTEuMC5kdGQiPgo8cGxpc3QgdmVyc2lvbj0iMS4wIj4KICA8ZGljdD4KICAgIDxrZXk+TWVzc2FnZVR5cGU8L2tleT4KICAgIDxzdHJpbmc+TGlzdGVuPC9zdHJpbmc+CiAgICA8a2V5PkNsaWVudFZlcnNpb25TdHJpbmc8L2tleT4KICAgIDxzdHJpbmc+dXNibXV4LWNsaWVudDwvc3RyaW5nPgogICAgPGtleT5Qcm9nTmFtZTwva2V5PgogICAgPHN0cmluZz51c2JtdXgtY2xpZW50PC9zdHJpbmc+CiAgPC9kaWN0Pgo8L3BsaXN0Pg==", "base64") | ||
}; | ||
|
||
describe("Usbmux-client unit tests", () => { | ||
|
||
let serverSocket: net.Socket | undefined; | ||
|
||
const mockServer = makeDestroyable(net.createServer((socket) => { | ||
if (serverSocket) serverSocket.destroy(); | ||
serverSocket = socket; | ||
})); | ||
let mockServerPort: number | undefined; | ||
|
||
let client: UsbmuxClient | undefined; | ||
|
||
beforeEach(async () => { | ||
mockServer.listen(0); | ||
mockServerPort = (mockServer.address() as net.AddressInfo).port; | ||
}); | ||
|
||
afterEach(async () => { | ||
client?.close(); | ||
client = undefined; | ||
|
||
await mockServer.destroy(); | ||
serverSocket = undefined; | ||
}); | ||
|
||
it.only("should send a hello message to start listening", async () => { | ||
getUsbmuxClient({ port: mockServerPort! }); | ||
|
||
await delay(10); | ||
const receivedData = serverSocket!.read(); | ||
|
||
expect(receivedData).to.deep.equal(MESSAGES.LISTEN_REQUEST); | ||
}); | ||
|
||
}); |