mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
feat: change autodetect output to a function
This commit is contained in:
parent
34ccc2edee
commit
d7a855da8b
2 changed files with 18 additions and 18 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { assert, shouldReject } from '../test/assert'
|
||||
import { makeTestFeature } from '../test/makeTestFeature'
|
||||
import { BindingInterface, OpenOptions, PortInfo, SetOptions } from './binding-interface'
|
||||
import Binding, { AllBindingClasses } from './index'
|
||||
import { autoDetect, AllBindingClasses } from './index'
|
||||
import MockBinding from '@serialport/binding-mock'
|
||||
|
||||
const defaultOpenOptions: OpenOptions = Object.freeze({
|
||||
|
|
@ -37,7 +37,7 @@ const listFields = ['path', 'manufacturer', 'serialNumber', 'pnpId', 'locationId
|
|||
const readyData = Buffer.from('READY')
|
||||
|
||||
testBinding('mock', MockBinding, '/dev/exists')
|
||||
testBinding(process.platform, Binding, process.env.TEST_PORT)
|
||||
testBinding(process.platform, autoDetect(), process.env.TEST_PORT)
|
||||
|
||||
function testBinding(bindingName: string, Binding: AllBindingClasses, testPort?: string) {
|
||||
const { testFeature, testHardware, describeHardware } = makeTestFeature(bindingName, testPort)
|
||||
|
|
@ -52,7 +52,6 @@ function testBinding(bindingName: string, Binding: AllBindingClasses, testPort?:
|
|||
describe('static method', () => {
|
||||
describe('.list', () => {
|
||||
it('returns an array', async () => {
|
||||
console.log({ Binding })
|
||||
const ports = await Binding.list()
|
||||
assert.isArray(ports)
|
||||
})
|
||||
|
|
|
|||
31
lib/index.ts
31
lib/index.ts
|
|
@ -12,19 +12,20 @@ export * from './binding-interface'
|
|||
|
||||
export type AllBindingClasses = typeof WindowsBinding | typeof DarwinBinding | typeof LinuxBinding
|
||||
export type AllBindings = WindowsBinding | DarwinBinding | LinuxBinding
|
||||
let binding: AllBindingClasses
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
debug('loading WindowsBinding')
|
||||
binding = WindowsBinding
|
||||
break
|
||||
case 'darwin':
|
||||
debug('loading DarwinBinding')
|
||||
binding = DarwinBinding
|
||||
break
|
||||
default:
|
||||
debug('loading LinuxBinding')
|
||||
binding = LinuxBinding
|
||||
}
|
||||
|
||||
export default binding
|
||||
/**
|
||||
* This is an auto detected binding for your current platform
|
||||
*/
|
||||
export const autoDetect = (): AllBindingClasses => {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
debug('loading WindowsBinding')
|
||||
return WindowsBinding
|
||||
case 'darwin':
|
||||
debug('loading DarwinBinding')
|
||||
return DarwinBinding
|
||||
default:
|
||||
debug('loading LinuxBinding')
|
||||
return LinuxBinding
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue