test: share process platform spy helper

This commit is contained in:
Vincent Koc
2026-05-17 16:36:35 +08:00
parent 3c1c850c02
commit 46061442e7
8 changed files with 31 additions and 91 deletions

View File

@@ -40,13 +40,17 @@ export function withRestoredMocks<T>(
}
}
export function mockProcessPlatform(platform: NodeJS.Platform): RestorableMock {
return vi.spyOn(process, "platform", "get").mockReturnValue(platform);
}
export function withMockedPlatform<T>(platform: NodeJS.Platform, run: () => Promise<T>): Promise<T>;
export function withMockedPlatform<T>(platform: NodeJS.Platform, run: () => T): T;
export function withMockedPlatform<T>(
platform: NodeJS.Platform,
run: () => T | Promise<T>,
): T | Promise<T> {
return withRestoredMocks([vi.spyOn(process, "platform", "get").mockReturnValue(platform)], run);
return withRestoredMocks([mockProcessPlatform(platform)], run);
}
export function withMockedWindowsPlatform<T>(run: () => Promise<T>): Promise<T>;