1+ import { describe , it , expect , jest } from '@jest/globals' ;
2+
3+ jest . mock ( 'fs' , ( ) => ( {
4+ __esModule : true ,
5+ default : {
6+ existsSync : jest . fn ( ) ,
7+ } ,
8+ } ) ) ;
9+ import fs from 'fs' ;
10+ import ExecutableCollector from '../src/collector' ;
11+
12+ const mockExistsSync = jest . spyOn ( fs , 'existsSync' ) ;
13+
14+ describe ( 'ExecutableCollector' , ( ) => {
15+ beforeEach ( ( ) => {
16+ mockExistsSync . mockReset ( ) ;
17+ } ) ;
18+
19+ it ( 'should return paths for existing executables across different triples' , ( ) => {
20+ mockExistsSync . mockImplementation ( ( filePath : unknown ) => {
21+ const existingPaths = [
22+ '.build/arm64-apple-macosx/release/myExecutable' ,
23+ '.build/x86_64-apple-macosx/release/myExecutable' ,
24+ ] ;
25+ return existingPaths . includes ( filePath as string ) ;
26+ }
27+ ) ;
28+
29+ const collector = new ExecutableCollector ( 'myExecutable' ) ;
30+ const result = collector . collect ( ) ;
31+ expect ( result ) . toEqual ( [
32+ '.build/arm64-apple-macosx/release/myExecutable' ,
33+ '.build/x86_64-apple-macosx/release/myExecutable' ,
34+ ] ) ;
35+ } ) ;
36+
37+ it ( 'should return an empty array if no executables exist' , ( ) => {
38+ ( fs . existsSync as jest . Mock ) . mockImplementation ( ( _ ) => false ) ;
39+
40+ const collector = new ExecutableCollector ( 'myExecutable' ) ;
41+ const result = collector . collect ( ) ;
42+ expect ( result ) . toEqual ( [ ] ) ;
43+ } ) ;
44+
45+ it ( 'should support different configurations' , ( ) => {
46+ mockExistsSync . mockImplementation ( ( filePath : unknown ) => {
47+ return filePath === '.build/arm64-apple-macosx/debug/myExecutable' ;
48+ } ) ;
49+
50+ const collector = new ExecutableCollector ( 'myExecutable' ) ;
51+ const result = collector . collect ( 'debug' ) ;
52+ expect ( result ) . toEqual ( [ '.build/arm64-apple-macosx/debug/myExecutable' ] ) ;
53+ } ) ;
54+ } ) ;
0 commit comments