test: strengthen regression coverage and trim low-value checks

This commit is contained in:
Peter Steinberger
2026-03-22 07:37:17 +00:00
parent f537ea90ed
commit b4656f193a
28 changed files with 656 additions and 212 deletions

View File

@@ -14,13 +14,20 @@ function mockProcReads(entries: Record<string, string>) {
}
async function withLinuxProcessPlatform<T>(run: () => Promise<T>): Promise<T> {
return withProcessPlatform("linux", run);
}
async function withProcessPlatform<T>(
platform: NodeJS.Platform,
run: () => Promise<T>,
): Promise<T> {
const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, "platform");
if (!originalPlatformDescriptor) {
throw new Error("missing process.platform descriptor");
}
Object.defineProperty(process, "platform", {
...originalPlatformDescriptor,
value: "linux",
value: platform,
});
try {
vi.resetModules();
@@ -102,12 +109,10 @@ describe("getProcessStartTime", () => {
});
it("returns null on non-Linux platforms", () => {
if (process.platform === "linux") {
// On actual Linux, this test is trivially satisfied by the other tests.
expect(true).toBe(true);
return;
}
expect(getProcessStartTime(process.pid)).toBeNull();
return withProcessPlatform("darwin", async () => {
const { getProcessStartTime: fresh } = await import("./pid-alive.js");
expect(fresh(process.pid)).toBeNull();
});
});
it("returns null for invalid PIDs", () => {