Skip to content

Commit 36d0178

Browse files
committed
working
1 parent 1145929 commit 36d0178

File tree

1 file changed

+53
-40
lines changed

1 file changed

+53
-40
lines changed

test/unit/node/util.test.ts

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { getEnvPaths, Paths } from "../../../src/node/util"
2-
31
/*
42
53
TODOS
@@ -15,42 +13,14 @@ runtime: /tmp/runtime
1513
1614
*/
1715

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)
3816
describe("getEnvPaths", () => {
39-
afterAll(() => {
40-
jest.clearAllMocks()
41-
jest.resetModules()
42-
})
43-
it("should return an object with the data, config and runtime path", () => {
44-
const actualPaths = getEnvPaths()
45-
const expectedProperties = ["data", "config", "runtime"]
46-
expectedProperties.forEach((property) => {
47-
expect(actualPaths[property as keyof Paths]).toBeDefined()
48-
})
49-
})
50-
5117
describe("on darwin", () => {
5218
let ORIGINAL_PLATFORM = ""
53-
19+
let getEnvPaths: () => {
20+
data: string
21+
config: string
22+
runtime: string
23+
}
5424
beforeAll(() => {
5525
ORIGINAL_PLATFORM = process.platform
5626

@@ -59,6 +29,28 @@ describe("getEnvPaths", () => {
5929
})
6030
})
6131

32+
beforeEach(() => {
33+
jest.mock("xdg-basedir", () => ({
34+
data: "/home/usr/.local/share",
35+
config: "/home/usr/.config",
36+
runtime: "/tmp/runtime",
37+
}))
38+
39+
jest.mock("env-paths", () => {
40+
return () => ({
41+
data: "/home/envPath/.local/share",
42+
config: "/home/envPath/.config",
43+
temp: "/tmp/envPath/runtime",
44+
})
45+
})
46+
47+
getEnvPaths = require("../../../src/node/util").getEnvPaths
48+
})
49+
50+
afterEach(() => {
51+
jest.resetModules()
52+
})
53+
6254
afterAll(() => {
6355
// Restore old platform
6456

@@ -78,16 +70,37 @@ describe("getEnvPaths", () => {
7870

7971
describe("on darwin", () => {
8072
let ORIGINAL_PLATFORM = ""
81-
73+
let getEnvPaths: () => {
74+
data: string
75+
config: string
76+
runtime: string
77+
}
8278
beforeAll(() => {
83-
jest.unmock("xdg-basedir")
8479
ORIGINAL_PLATFORM = process.platform
8580

8681
Object.defineProperty(process, "platform", {
8782
value: "darwin",
8883
})
8984
})
9085

86+
beforeEach(() => {
87+
jest.mock("xdg-basedir", () => ({}))
88+
89+
jest.mock("env-paths", () => {
90+
return () => ({
91+
data: "/home/envPath/.local/share",
92+
config: "/home/envPath/.config",
93+
temp: "/tmp/envPath/runtime",
94+
})
95+
})
96+
97+
getEnvPaths = require("../../../src/node/util").getEnvPaths
98+
})
99+
100+
afterEach(() => {
101+
jest.resetModules()
102+
})
103+
91104
afterAll(() => {
92105
// Restore old platform
93106

@@ -99,9 +112,9 @@ describe("getEnvPaths", () => {
99112
it("should return the env paths using envPaths", () => {
100113
const envPaths = getEnvPaths()
101114

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")
115+
expect(envPaths.data).toEqual("/home/envPath/.local/share")
116+
expect(envPaths.config).toEqual("/home/envPath/.config")
117+
expect(envPaths.runtime).toEqual("/tmp/envPath/runtime")
105118
})
106119
})
107120
})

0 commit comments

Comments
 (0)