Skip to content

Commit f24f9db

Browse files
committed
Implement executable_collector test
1 parent 0bb66eb commit f24f9db

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/collector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs';
1+
import fs from 'fs';
22

33
class ExecutableCollector {
44
private executableName: string;

test/executable_collector.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)