node-serialport-bindings-cpp/lib/binding-interface.test.ts
Francis Gulotta 2a93f48ee6
feat: migrate to typescript (#3)
This change migrates to typescript. The tests have been modified to conform to typescript and to cleanup cases when they weren't actually working (only one or two cases).

I've defined the existing bindings interface for all platforms. There are changes I'd love to make but didn't here (update/set/get/getBaudRate etc are messy). This should in theory be a drop in for the existing bindings. If there are bugs I imagine they're type related not functionality.

I dropped abstract bindings as having it a separate package didn't make sense during the refactor. I'd like to iterate on the design a bit more before returning to that class. Mockbinding may also now be drifted slightly from this package. I'll clean those inconsistencies up when I upgrade the main repo.
2022-01-22 15:55:03 -05:00

42 lines
1.3 KiB
TypeScript

import { BindingInterface, OpenOptions, PortStatus, SetOptions, UpdateOptions } from './binding-interface'
import { shouldReject } from '../test/assert'
class Mock extends BindingInterface {
isOpen: boolean
open(_path: string, _options?: OpenOptions): Promise<void> {
throw new Error('Method not implemented.')
}
close(): Promise<void> {
throw new Error('Method not implemented.')
}
read(_buffer: Buffer, _offset: number, _length: number): Promise<{ buffer: Buffer; bytesRead: number }> {
throw new Error('Method not implemented.')
}
write(_buffer: Buffer): Promise<void> {
throw new Error('Method not implemented.')
}
update(_options: UpdateOptions): Promise<void> {
throw new Error('Method not implemented.')
}
set(_options: SetOptions): Promise<void> {
throw new Error('Method not implemented.')
}
get(): Promise<PortStatus> {
throw new Error('Method not implemented.')
}
getBaudRate(): Promise<{ baudRate: number }> {
throw new Error('Method not implemented.')
}
flush(): Promise<void> {
throw new Error('Method not implemented.')
}
drain(): Promise<void> {
throw new Error('Method not implemented.')
}
}
describe('BindingInterface', () => {
it('throws on unimplemented list', async () => {
await shouldReject(Mock.list(), Error, 'List should throw if not implemented')
})
})