Skip to content

Commit 1145929

Browse files
committed
wip
1 parent f1969bb commit 1145929

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

test/unit/node/util.test.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,107 @@
11
import { getEnvPaths, Paths } from "../../../src/node/util"
22

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)
338
describe("getEnvPaths", () => {
39+
afterAll(() => {
40+
jest.clearAllMocks()
41+
jest.resetModules()
42+
})
443
it("should return an object with the data, config and runtime path", () => {
544
const actualPaths = getEnvPaths()
645
const expectedProperties = ["data", "config", "runtime"]
746
expectedProperties.forEach((property) => {
847
expect(actualPaths[property as keyof Paths]).toBeDefined()
948
})
1049
})
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+
})
11107
})

0 commit comments

Comments
 (0)