11import { describe , it , expect , jest , beforeEach } from '@jest/globals' ;
22import { EventEmitter } from 'events' ;
3+ import {
4+ createFindBinaryMock ,
5+ joinWithSeparator ,
6+ } from './test-utils/pathResolutionMocks.js' ;
37
48type PathStyle = 'posix' | 'win32' ;
59
@@ -8,11 +12,6 @@ type SetupOptions = {
812 isPackagedRuntime : boolean ;
913} ;
1014
11- const makeJoin = ( style : PathStyle ) => {
12- const sep = style === 'win32' ? '\\' : '/' ;
13- return ( ...parts : string [ ] ) => parts . join ( sep ) ;
14- } ;
15-
1615async function setupAndImportConverterManager ( options : SetupOptions ) {
1716 jest . resetModules ( ) ;
1817
@@ -22,7 +21,8 @@ async function setupAndImportConverterManager(options: SetupOptions) {
2221 console . warn = jest . fn ( ) ;
2322 console . error = jest . fn ( ) ;
2423
25- const join = makeJoin ( options . pathStyle ) ;
24+ const sep = options . pathStyle === 'win32' ? '\\' : '/' ;
25+ const join = joinWithSeparator ( sep ) ;
2626 const moduleDir = options . pathStyle === 'win32' ? 'C:\\MODDIR' : '/MODDIR' ;
2727 const cwdDir = options . pathStyle === 'win32' ? 'C:\\CWD' : '/CWD' ;
2828 const runtimeBaseDir =
@@ -78,18 +78,12 @@ async function setupAndImportConverterManager(options: SetupOptions) {
7878 getAnswer : jest . fn ( async ( ) => '' ) ,
7979 runtimeBaseDir,
8080 isPackagedRuntime : options . isPackagedRuntime ,
81- findBinary : ( name : string , subdirs : string [ ] = [ ] ) => {
82- const roots = [ runtimeBaseDir , cwdDir ] ;
83- for ( const root of roots ) {
84- const direct = join ( root , name ) ;
85- if ( existsSyncMock ( direct ) ) return direct ;
86- for ( const sub of subdirs ) {
87- const candidate = join ( root , sub , name ) ;
88- if ( existsSyncMock ( candidate ) ) return candidate ;
89- }
90- }
91- return null ;
92- } ,
81+ findBinary : createFindBinaryMock ( {
82+ sep,
83+ runtimeBaseDir,
84+ pathExists : ( path : string ) => existsSyncMock ( path ) ,
85+ includeCwd : true ,
86+ } ) ,
9387 } ) ) ;
9488
9589 const cwdSpy = jest . spyOn ( process , 'cwd' ) . mockReturnValue ( cwdDir ) ;
0 commit comments