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
+4 -15
View File
@@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js";
import { makeTempWorkspace } from "../test-helpers/workspace.js";
import { captureEnv } from "../test-utils/env.js";
import { mockProcessPlatform } from "../test-utils/vitest-spies.js";
import type { GatewayService } from "./service.js";
import {
describeGatewayServiceRestart,
@@ -14,24 +15,12 @@ import {
} from "./service.js";
import { createMockGatewayService } from "./service.test-helpers.js";
const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, "platform");
function setPlatform(value: NodeJS.Platform | "aix") {
if (!originalPlatformDescriptor) {
throw new Error("missing process.platform descriptor");
}
Object.defineProperty(process, "platform", {
configurable: true,
enumerable: originalPlatformDescriptor.enumerable ?? false,
value,
});
function setPlatform(value: NodeJS.Platform) {
mockProcessPlatform(value);
}
afterEach(() => {
if (!originalPlatformDescriptor) {
return;
}
Object.defineProperty(process, "platform", originalPlatformDescriptor);
vi.restoreAllMocks();
});
function createService(overrides: Partial<GatewayService> = {}): GatewayService {