test: tighten wsl detection coverage
This commit is contained in:
parent
4eb279036a
commit
576134ec73
@ -59,6 +59,13 @@ describe("wsl detection", () => {
|
||||
expect(readFileSyncMock).toHaveBeenCalledWith("/proc/version", "utf8");
|
||||
});
|
||||
|
||||
it("returns false when sync detection cannot read /proc/version", () => {
|
||||
readFileSyncMock.mockImplementationOnce(() => {
|
||||
throw new Error("ENOENT");
|
||||
});
|
||||
expect(isWSLSync()).toBe(false);
|
||||
});
|
||||
|
||||
it.each(["Linux version 6.6.0-1-microsoft-standard-WSL2", "Linux version 6.6.0-1-wsl2"])(
|
||||
"detects WSL2 sync from kernel version: %s",
|
||||
(kernelVersion) => {
|
||||
@ -68,6 +75,12 @@ describe("wsl detection", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("returns false for WSL2 sync when WSL is detected but no WSL2 markers exist", () => {
|
||||
readFileSyncMock.mockReturnValueOnce("Linux version 4.4.0-19041-Microsoft");
|
||||
readFileSyncMock.mockReturnValueOnce("Linux version 4.4.0-19041-Microsoft");
|
||||
expect(isWSL2Sync()).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for sync detection on non-linux platforms", () => {
|
||||
setPlatform("darwin");
|
||||
expect(isWSLSync()).toBe(false);
|
||||
@ -88,6 +101,13 @@ describe("wsl detection", () => {
|
||||
expect(readFileMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("short-circuits async detection from WSL env vars without reading osrelease", async () => {
|
||||
process.env.WSL_DISTRO_NAME = "Ubuntu";
|
||||
|
||||
await expect(isWSL()).resolves.toBe(true);
|
||||
expect(readFileMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns false when async WSL detection cannot read osrelease", async () => {
|
||||
readFileMock.mockRejectedValueOnce(new Error("ENOENT"));
|
||||
await expect(isWSL()).resolves.toBe(false);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user