11import { assert , shouldReject } from '../test/assert'
22import { mockLinuxList as linuxList , mockLinuxListError } from './mocks/linux-list'
3+ import fs from 'fs'
4+ import sinon from 'sinon'
35
46const mockUdevOutput = String . raw `
57P: /devices/platform/serial8250/tty/ttyS0
@@ -27,8 +29,8 @@ E: DEVNAME=/dev/ttyACM0
2729E: DEVPATH=/devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/tty/ttyACM0
2830E: ID_BUS=usb
2931E: ID_MM_CANDIDATE=1
30- E: ID_MODEL=0043
31- E: ID_MODEL_ENC=0043
32+ E: ID_MODEL=Arduino_Uno
33+ E: ID_MODEL_ENC=Arduino\x20Uno
3234E: ID_MODEL_FROM_DATABASE=Uno R3 (CDC ACM)
3335E: ID_MODEL_ID=0043
3436E: ID_PATH=pci-0000:00:06.0-usb-0:2:1.0
@@ -75,14 +77,9 @@ N: ttyNOTASERIALPORT
7577`
7678
7779const portOutput = [
78- {
79- path : '/dev/ttyS0' ,
80- } ,
81- {
82- path : '/dev/ttyS1' ,
83- } ,
8480 {
8581 path : '/dev/ttyACM0' ,
82+ friendlyName : 'Arduino Uno' ,
8683 manufacturer : 'Arduino (www.arduino.cc)' ,
8784 serialNumber : '752303138333518011C1' ,
8885 productId : '0043' ,
@@ -93,17 +90,25 @@ const portOutput = [
9390 path : '/dev/ttyAMA_im_a_programmer' ,
9491 pnpId : 'pci-NATA_Siolynx2_C8T6VI1F-if00-port0' ,
9592 } ,
96- {
97- path : '/dev/ttyMFD0' ,
98- vendorId : '2343' ,
99- productId : '0043' ,
100- } ,
101- {
102- path : '/dev/rfcomm4' ,
103- } ,
10493]
10594
10695describe ( 'listLinux' , ( ) => {
96+ let readdirSyncStub : sinon . SinonStub
97+ let realpathSyncStub : sinon . SinonStub
98+
99+ beforeEach ( ( ) => {
100+ readdirSyncStub = sinon . stub ( fs , 'readdirSync' )
101+ realpathSyncStub = sinon . stub ( fs , 'realpathSync' )
102+
103+ readdirSyncStub . withArgs ( '/dev/serial/by-path' ) . returns ( [ 'pci-0000:00:06.0-usb-0:2:1.0' , 'pci-NATA_Siolynx2_C8T6VI1F-if00-port0' ] )
104+ realpathSyncStub . withArgs ( '/dev/serial/by-path/pci-0000:00:06.0-usb-0:2:1.0' ) . returns ( '/dev/ttyACM0' )
105+ realpathSyncStub . withArgs ( '/dev/serial/by-path/pci-NATA_Siolynx2_C8T6VI1F-if00-port0' ) . returns ( '/dev/ttyAMA_im_a_programmer' )
106+ } )
107+
108+ afterEach ( ( ) => {
109+ sinon . restore ( )
110+ } )
111+
107112 it ( 'lists available serialports' , async ( ) => {
108113 const ports = await linuxList ( mockUdevOutput )
109114 assert . containSubset ( ports , portOutput )
0 commit comments