|
1 | 1 | import { getEnvPaths, Paths } from "../../../src/node/util"
|
2 | 2 |
|
| 3 | +/* |
| 4 | +
|
| 5 | +TODOS |
| 6 | +
|
| 7 | +- [x] add logic to overwrite process.platform |
| 8 | +- [x] mock xdgBasedir |
| 9 | +
|
| 10 | +stuck...can't mock module |
| 11 | +
|
| 12 | +data: /home/sindresorhus/.local/share |
| 13 | +config: /home/sindresorhus/.config |
| 14 | +runtime: /tmp/runtime |
| 15 | +
|
| 16 | +*/ |
| 17 | + |
| 18 | +// jest.mock("env-paths", () => ({ |
| 19 | +// data: "/home/envPath/.local/share", |
| 20 | +// config: "/home/envPath/.config", |
| 21 | +// runtime: "/tmp/envPath/runtime", |
| 22 | +// })) |
| 23 | + |
| 24 | +jest.mock("xdg-basedir", () => ({ |
| 25 | + data: "/home/usr/.local/share", |
| 26 | + config: "/home/usr/.config", |
| 27 | + runtime: "/tmp/runtime", |
| 28 | +})) |
| 29 | + |
| 30 | +jest.mock("env-paths", () => { |
| 31 | + return () => ({ |
| 32 | + data: "yo", |
| 33 | + config: "yo", |
| 34 | + runtime: "yo", |
| 35 | + }) |
| 36 | +}) |
| 37 | +// jest.mock("env-paths", () => mockedEnvPaths) |
3 | 38 | describe("getEnvPaths", () => {
|
| 39 | + afterAll(() => { |
| 40 | + jest.clearAllMocks() |
| 41 | + jest.resetModules() |
| 42 | + }) |
4 | 43 | it("should return an object with the data, config and runtime path", () => {
|
5 | 44 | const actualPaths = getEnvPaths()
|
6 | 45 | const expectedProperties = ["data", "config", "runtime"]
|
7 | 46 | expectedProperties.forEach((property) => {
|
8 | 47 | expect(actualPaths[property as keyof Paths]).toBeDefined()
|
9 | 48 | })
|
10 | 49 | })
|
| 50 | + |
| 51 | + describe("on darwin", () => { |
| 52 | + let ORIGINAL_PLATFORM = "" |
| 53 | + |
| 54 | + beforeAll(() => { |
| 55 | + ORIGINAL_PLATFORM = process.platform |
| 56 | + |
| 57 | + Object.defineProperty(process, "platform", { |
| 58 | + value: "darwin", |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + afterAll(() => { |
| 63 | + // Restore old platform |
| 64 | + |
| 65 | + Object.defineProperty(process, "platform", { |
| 66 | + value: ORIGINAL_PLATFORM, |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + it("should return the env paths using xdgBasedir", () => { |
| 71 | + const envPaths = getEnvPaths() |
| 72 | + |
| 73 | + expect(envPaths.data).toEqual("/home/usr/.local/share/code-server") |
| 74 | + expect(envPaths.config).toEqual("/home/usr/.config/code-server") |
| 75 | + expect(envPaths.runtime).toEqual("/tmp/runtime/code-server") |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + describe("on darwin", () => { |
| 80 | + let ORIGINAL_PLATFORM = "" |
| 81 | + |
| 82 | + beforeAll(() => { |
| 83 | + jest.unmock("xdg-basedir") |
| 84 | + ORIGINAL_PLATFORM = process.platform |
| 85 | + |
| 86 | + Object.defineProperty(process, "platform", { |
| 87 | + value: "darwin", |
| 88 | + }) |
| 89 | + }) |
| 90 | + |
| 91 | + afterAll(() => { |
| 92 | + // Restore old platform |
| 93 | + |
| 94 | + Object.defineProperty(process, "platform", { |
| 95 | + value: ORIGINAL_PLATFORM, |
| 96 | + }) |
| 97 | + }) |
| 98 | + |
| 99 | + it("should return the env paths using envPaths", () => { |
| 100 | + const envPaths = getEnvPaths() |
| 101 | + |
| 102 | + expect(envPaths.data).toEqual("/home/envPath/.local/share/code-server") |
| 103 | + expect(envPaths.config).toEqual("/home/envPath/.config/code-server") |
| 104 | + expect(envPaths.runtime).toEqual("/tmp/envPath/runtime/code-server") |
| 105 | + }) |
| 106 | + }) |
11 | 107 | })
|
0 commit comments