Replies: 2 comments
-
Sorry I missed the tests in export class DummyHID extends EventEmitter implements HIDDevice {
public path: string
oninputreport: (this: this, ev: HIDInputReportEvent) => unknown
opened: boolean
vendorId: number
productId: number
productName: string
collections: HIDCollectionInfo[]
/** An array containing the status of the buttons */
buttonsStatus: (1 | 0)[]
constructor(devicePath?: string) {
super()
if (typeof devicePath !== 'string') {
devicePath = '/dev/hidraw' + deviceCounter++
}
this.path = devicePath
this.opened = false
this.vendorId = 4057 // Elgato vendor ID
this.productId = 0x006d // Elgato Stream Deck Original v2 product ID
this.productName = 'MOCK Elgato Stream Deck Original v2'
this.buttonsStatus = new Array(16).fill(0)
}
/** add-on functions - which don't seem to be working */
async keyPress(keyNum: KeyIndex, holdTimeMs = 100): Promise<void> {
console.log(`keyPress(${keyNum}, ${holdTimeMs})`)
this.keyDown(keyNum)
await new Promise((resolve) => setTimeout(resolve, holdTimeMs))
this.keyUp(keyNum)
}
keyDown(keyNum: KeyIndex): void {
console.log(`keyDown(${keyNum})`)
this.buttonsStatus[keyNum] = 1
this.emit('input', this.buttonsStatus)
}
keyUp(keyNum: KeyIndex): void {
console.log(`keyUp(${keyNum})`)
this.buttonsStatus[keyNum] = 0
this.emit('input', this.buttonsStatus)
}
async open(): Promise<void> {
console.log(`DummyHID.open()`)
this.opened = true
}
async sendReport(reportId: number, data: BufferSource): Promise<void> {
console.log(`DummyHID.sendReport(${reportId}, BufferSource)`)
}
async receiveFeatureReport(reportId: number): Promise<DataView> {
if (reportId === 5) {
// get Firmware Version
const buffer = new Uint16Array([
5, 12, 254, 90, 239, 250, 49, 46, 48, 48, 46, 48, 48, 52, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]).buffer
return new DataView(buffer)
} else if (reportId === 6) {
// get Serial Number
const buffer = new Uint16Array([
6, 12, 67, 76, 49, 56, 73, 49, 65, 48, 48, 57, 49, 51, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]).buffer
return new DataView(buffer)
} else {
const buffer = new Uint16Array([0, 1, 2, 3]).buffer
return new DataView(buffer)
}
}
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
): void
addEventListener(
type: string,
listener: (...args: unknown[]) => void,
options?: AddEventListenerOptions
): void {
super.addListener(type, listener, options)
}
removeEventListener(
type: string,
callback: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions
): void
removeEventListener(
type: string,
callback: (...args: unknown[]) => void,
options?: unknown
): void {
super.removeListener(type, callback, options)
}
dispatchEvent(event: Event): boolean {
console.log(`DummyHID.dispatchEvent(${event})`)
return this.emit(event.type, event)
}
public async close(): Promise<void> {
console.log(`DummyHID.close()`)
this.opened = false
}
public pause(): void {
console.log(`DummyHID.pause()`)
}
public read(_callback: (err: unknown, data: number[]) => void): void {
console.log(`DummyHID.read()`)
}
public readSync(): number[] {
return []
}
public readTimeout(_timeOut: number): number[] {
return []
}
public async sendFeatureReport(
reportId: number,
data: BufferSource
): Promise<void> {
console.log(`DummyHID.sendFeatureReport(${reportId}, BufferSource)`)
}
public getFeatureReport(reportId: number, reportLength: number): number[] {
if (reportId === 5 && reportLength === 32) {
// get Firmware Version
return [
5, 12, 254, 90, 239, 250, 49, 46, 48, 48, 46, 48, 48, 52, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]
} else if (reportId === 6 && reportLength === 32) {
// get Serial Number
return [
6, 12, 67, 76, 49, 56, 73, 49, 65, 48, 48, 57, 49, 51, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]
} else {
return [0, 1, 2, 3]
}
}
public resume(): void {
console.log(`DummyHID.resume()`)
}
// on (event: string, handler: (value: any) => void) {
// throw new Error('Not implemented')
// }
public write(_values: number[]): number {
console.log(`DummyHID.write(${_values})`)
return 1
}
public setDriverType(_type: string): void {
console.log(`DummyHID.setDriverType(${_type})`)
}
public setNonBlocking(_no_block: boolean): void {
console.log(`DummyHID.setNonBlocking(${_no_block})`)
}
} |
Beta Was this translation helpful? Give feedback.
-
Im not sure what should be done for this. I havent tried to mock this library yet, but for other connection libraries I generally find it works well to mock the exposed interface of the library. You can do as you have and provide an alternate HIDDevice implementation, but then your tests will have to be a bit aware of the protocol the streamdecks use, which is extra work, and could break in an update of this library. Maybe this library should expose the information about the different models better, so that you dont have to know all the details about each model. Or perhaps it could provide a minimal implementation for each model with all those fields filled out, and all the methods which 'write' to the device set to do nothing. Would one of those options be helpful? |
Beta Was this translation helpful? Give feedback.
-
I'm interested in doing (WebHID) Stream Deck testing in my Playwright E2E tests. It seems like the best way to do this would be to have a library that could generate virtual Stream Deck (or generic WebHID) devices. This way I could add one or more mock devices to emit key down/up and receive data from
node-elgato-stream-deck
to check that everything is working - without needing actual devices connected to the test computer.Does anyone have any thoughts or clues about this? I don't know that this needs to be a part of the
node-elgato-stream-deck
package. It could be a separate library. But some automated testing tools around this library sure would be nice to have.Beta Was this translation helpful? Give feedback.
All reactions