Skip to content

Commit 28c6838

Browse files
committed
Add test to validate.
1 parent 0406a1e commit 28c6838

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/handlers/pathHandlers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export function registerPathHandlers() {
3434
// Remove OneDrive from documents path if present
3535
if (process.platform === 'win32') {
3636
documentsPath = documentsPath.replace(/OneDrive\\/, '');
37+
// We should use path.win32.join for Windows paths
38+
return {
39+
appData: app.getPath('appData'),
40+
appPath: app.getAppPath(),
41+
defaultInstallPath: path.win32.join(documentsPath, 'ComfyUI'),
42+
};
3743
}
3844

3945
return {

tests/unit/handlers/pathHandler.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,32 @@ const getRegisteredHandler = <T extends (...args: never[]) => unknown>(
110110
return handler as unknown as HandlerType<T>;
111111
};
112112

113+
type ElectronPathName =
114+
| 'home'
115+
| 'appData'
116+
| 'userData'
117+
| 'sessionData'
118+
| 'temp'
119+
| 'exe'
120+
| 'module'
121+
| 'desktop'
122+
| 'documents'
123+
| 'downloads'
124+
| 'music'
125+
| 'pictures'
126+
| 'videos'
127+
| 'recent'
128+
| 'logs'
129+
| 'crashDumps';
130+
131+
const mockPaths = (overrides: Partial<Record<ElectronPathName, string>> = {}) => {
132+
vi.mocked(app.getPath).mockImplementation((name: ElectronPathName): string => {
133+
if (name in overrides) return overrides[name]!;
134+
if (name in MOCK_PATHS) return MOCK_PATHS[name as keyof typeof MOCK_PATHS];
135+
return path.normalize(`/mock/${name}`);
136+
});
137+
};
138+
113139
describe('PathHandlers', () => {
114140
beforeEach(() => {
115141
vi.mocked(app.getPath).mockImplementation(
@@ -328,6 +354,19 @@ describe('PathHandlers', () => {
328354
defaultInstallPath: path.join('/mock/documents', 'ComfyUI'),
329355
});
330356
});
357+
358+
it('Windows: should remove OneDrive from documents path', async () => {
359+
// Mock Windows platform
360+
const restorePlatform = mockProcessPlatform('win32');
361+
mockPaths({ documents: String.raw`C:\Users\Test\OneDrive\Documents` });
362+
363+
const result = await getSystemPathsHandler({});
364+
const expected = String.raw`C:\Users\Test\Documents\ComfyUI`;
365+
expect(result.defaultInstallPath).toBe(expected);
366+
367+
// Restore original platform
368+
restorePlatform();
369+
});
331370
});
332371

333372
describe('validate-comfyui-source', () => {

0 commit comments

Comments
 (0)