diff --git a/src/node/util.ts b/src/node/util.ts index 429cba9654a1..b768ec05b8c8 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -58,10 +58,10 @@ export const paths = getEnvPaths() * On MacOS this function gets the standard XDG directories instead of using the native macOS * ones. Most CLIs do this as in practice only GUI apps use the standard macOS directories. */ -export function getEnvPaths(): Paths { +export function getEnvPaths(platform = process.platform): Paths { const paths = envPaths("code-server", { suffix: "" }) const append = (p: string): string => path.join(p, "code-server") - switch (process.platform) { + switch (platform) { case "darwin": return { // envPaths uses native directories so force Darwin to use the XDG spec diff --git a/test/unit/node/util.test.ts b/test/unit/node/util.test.ts index ef27418d7c31..6c184d1612e6 100644 --- a/test/unit/node/util.test.ts +++ b/test/unit/node/util.test.ts @@ -5,18 +5,8 @@ import { generateUuid } from "../../../src/common/util" import { tmpdir } from "../../../src/node/constants" import * as util from "../../../src/node/util" -describe.skip("getEnvPaths", () => { +describe("getEnvPaths", () => { describe("on darwin", () => { - let ORIGINAL_PLATFORM = "" - - beforeAll(() => { - ORIGINAL_PLATFORM = process.platform - - Object.defineProperty(process, "platform", { - value: "darwin", - }) - }) - beforeEach(() => { jest.resetModules() jest.mock("env-paths", () => { @@ -27,15 +17,6 @@ describe.skip("getEnvPaths", () => { }) }) }) - - afterAll(() => { - // Restore old platform - - Object.defineProperty(process, "platform", { - value: ORIGINAL_PLATFORM, - }) - }) - it("should return the env paths using xdgBasedir", () => { jest.mock("xdg-basedir", () => ({ data: "/home/usr/.local/share", @@ -43,7 +24,7 @@ describe.skip("getEnvPaths", () => { runtime: "/tmp/runtime", })) const getEnvPaths = require("../../../src/node/util").getEnvPaths - const envPaths = getEnvPaths() + const envPaths = getEnvPaths("darwin") expect(envPaths.data).toEqual("/home/usr/.local/share/code-server") expect(envPaths.config).toEqual("/home/usr/.config/code-server") @@ -53,7 +34,7 @@ describe.skip("getEnvPaths", () => { it("should return the env paths using envPaths when xdgBasedir is undefined", () => { jest.mock("xdg-basedir", () => ({})) const getEnvPaths = require("../../../src/node/util").getEnvPaths - const envPaths = getEnvPaths() + const envPaths = getEnvPaths("darwin") expect(envPaths.data).toEqual("/home/envPath/.local/share") expect(envPaths.config).toEqual("/home/envPath/.config") @@ -61,16 +42,6 @@ describe.skip("getEnvPaths", () => { }) }) describe("on win32", () => { - let ORIGINAL_PLATFORM = "" - - beforeAll(() => { - ORIGINAL_PLATFORM = process.platform - - Object.defineProperty(process, "platform", { - value: "win32", - }) - }) - beforeEach(() => { jest.resetModules() jest.mock("env-paths", () => { @@ -82,17 +53,9 @@ describe.skip("getEnvPaths", () => { }) }) - afterAll(() => { - // Restore old platform - - Object.defineProperty(process, "platform", { - value: ORIGINAL_PLATFORM, - }) - }) - it("should return the env paths using envPaths", () => { const getEnvPaths = require("../../../src/node/util").getEnvPaths - const envPaths = getEnvPaths() + const envPaths = getEnvPaths("win32") expect(envPaths.data).toEqual("/windows/envPath/.local/share") expect(envPaths.config).toEqual("/windows/envPath/.config") @@ -100,16 +63,6 @@ describe.skip("getEnvPaths", () => { }) }) describe("on other platforms", () => { - let ORIGINAL_PLATFORM = "" - - beforeAll(() => { - ORIGINAL_PLATFORM = process.platform - - Object.defineProperty(process, "platform", { - value: "linux", - }) - }) - beforeEach(() => { jest.resetModules() jest.mock("env-paths", () => { @@ -121,20 +74,12 @@ describe.skip("getEnvPaths", () => { }) }) - afterAll(() => { - // Restore old platform - - Object.defineProperty(process, "platform", { - value: ORIGINAL_PLATFORM, - }) - }) - it("should return the runtime using xdgBasedir if it exists", () => { jest.mock("xdg-basedir", () => ({ runtime: "/tmp/runtime", })) const getEnvPaths = require("../../../src/node/util").getEnvPaths - const envPaths = getEnvPaths() + const envPaths = getEnvPaths("linux") expect(envPaths.data).toEqual("/linux/envPath/.local/share") expect(envPaths.config).toEqual("/linux/envPath/.config") @@ -144,7 +89,7 @@ describe.skip("getEnvPaths", () => { it("should return the env paths using envPaths when xdgBasedir is undefined", () => { jest.mock("xdg-basedir", () => ({})) const getEnvPaths = require("../../../src/node/util").getEnvPaths - const envPaths = getEnvPaths() + const envPaths = getEnvPaths("linux") expect(envPaths.data).toEqual("/linux/envPath/.local/share") expect(envPaths.config).toEqual("/linux/envPath/.config")