import { MockSerialPort } from "@zwave-js/serial" ; import type { DeepPartial } from "@zwave-js/shared" ; import { Driver } from "../driver/Driver" ; import type { ZWaveOptions } from "../driver/ZWaveOptions" ; jest . mock ( "@zwave-js/serial" , ( ) => { const mdl = jest . requireActual ( "@zwave-js/serial" ) ; return { ... mdl , ZWaveSerialPort : mdl . MockSerialPort } ; } ) ; export const PORT_ADDRESS = "/tty/FAKE" ; /** Creates a real driver instance with a mocked serial port to enable end to end tests */ export async function createAndStartDriver ( options = { } ) { if ( ! options . logConfig ) { options . logConfig = { enabled : false } ; } const driver = new Driver ( PORT_ADDRESS , { ... options , interview : { skipInterview : true } } ) ; driver . on ( "error" , ( ) => { } ) ; driver . softReset = ( ) => new Promise ( ( ) => { } ) ; await driver . start ( ) ; const portInstance = MockSerialPort . getInstance ( PORT_ADDRESS ) ! ; portInstance . openStub . mockClear ( ) ; portInstance . closeStub . mockClear ( ) ; portInstance . writeStub . mockClear ( ) ; portInstance [ "_lastWrite" ] = undefined ; driver [ "_valueDB" ] = new Map ( ) as any ; driver [ "_valueDB" ] ! . close = ( ) => Promise . resolve ( ) ; driver [ "_metadataDB" ] = new Map ( ) as any ; driver [ "_metadataDB" ] ! . close = ( ) => Promise . resolve ( ) ; driver [ "_controller" ] = { ownNodeId : 1 , isFunctionSupported : ( ) => true , nodes : new Map ( ) , incrementStatistics : ( ) => { } } as any ; return { driver , serialport : portInstance } ; }