Skip to content

Commit bef76f1

Browse files
committed
test(shared): avoid real OS lookups in username tests
1 parent 487c251 commit bef76f1

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎packages/shared/src/HostProcess.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
// @effect-diagnostics nodeBuiltinImport:off
1+
// @effect-diagnostics nodeBuiltinImport:off -- tests replace the native OS lookup and sync its ESM bindings.
22
import * as NodeModule from "node:module";
3-
import * as NodeOS from "node:os";
3+
import type * as NodeOS from "node:os";
44
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
55

66
import * as HostProcess from "./HostProcess.ts";
77

88
const mutableOs = NodeModule.createRequire(import.meta.url)("node:os") as typeof NodeOS;
9+
const userInfo = {
10+
username: "remote-user",
11+
uid: 1000,
12+
gid: 1000,
13+
shell: null,
14+
homedir: "/home/remote-user",
15+
} satisfies NodeOS.UserInfo<string>;
916

1017
afterEach(() => {
1118
vi.restoreAllMocks();
@@ -14,7 +21,6 @@ afterEach(() => {
1421

1522
describe("Username", () => {
1623
it("uses the OS login account", () => {
17-
const userInfo = NodeOS.userInfo();
1824
vi.spyOn(mutableOs, "userInfo").mockReturnValue({ ...userInfo, username: " remote-user " });
1925
NodeModule.syncBuiltinESMExports();
2026
expect(HostProcess.Username.defaultValue()).toBe("remote-user");
@@ -29,7 +35,6 @@ describe("Username", () => {
2935
});
3036

3137
it("leaves an empty username unavailable", () => {
32-
const userInfo = NodeOS.userInfo();
3338
vi.spyOn(mutableOs, "userInfo").mockReturnValue({ ...userInfo, username: " " });
3439
NodeModule.syncBuiltinESMExports();
3540
expect(HostProcess.Username.defaultValue()).toBeNull();

0 commit comments

Comments
 (0)