Skip to content

Commit 7870c0b

Browse files
committed
fix: coveragePathIgnorePatterns to /out
We were accidentally ignoring `node/routes` because we had "out" instead of "/out" in `coveragePathIgnorePatterns` which caused us to not collect coverage for those files. Now we do.
1 parent 027106a commit 7870c0b

File tree

2 files changed

+65
-99
lines changed

2 files changed

+65
-99
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"clover"
143143
],
144144
"coveragePathIgnorePatterns": [
145-
"out"
145+
"/out"
146146
],
147147
"coverageThreshold": {
148148
"global": {

test/unit/constants.test.ts

+64-98
Original file line numberDiff line numberDiff line change
@@ -6,126 +6,92 @@ import { loggerModule } from "../utils/helpers"
66
jest.mock("@coder/logger", () => require("../utils/helpers").loggerModule)
77

88
describe("constants", () => {
9-
describe("getPackageJson", () => {
9+
beforeAll(() => {
10+
jest.clearAllMocks()
11+
jest.resetModules()
12+
})
13+
describe("with package.json defined", () => {
1014
const { getPackageJson } = require("../../src/node/constants")
11-
afterEach(() => {
12-
jest.clearAllMocks()
15+
let mockPackageJson = {
16+
name: "mock-code-server",
17+
description: "Run VS Code on a remote server.",
18+
repository: "https://github.com/cdr/code-server",
19+
version: "1.0.0",
20+
commit: "f6b2be2838f4afb217c2fd8f03eafedd8d55ef9b",
21+
}
22+
let version = ""
23+
let commit = ""
24+
25+
beforeEach(() => {
26+
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
27+
commit = require("../../src/node/constants").commit
28+
version = require("../../src/node/constants").version
1329
})
1430

1531
afterAll(() => {
16-
jest.restoreAllMocks()
32+
jest.clearAllMocks()
1733
jest.resetModules()
1834
})
1935

20-
it("should log a warning if package.json not found", () => {
21-
const expectedErrorMessage = "Cannot find module './package.json' from 'src/node/constants.ts'"
22-
23-
getPackageJson("./package.json")
24-
25-
expect(loggerModule.logger.warn).toHaveBeenCalled()
26-
expect(loggerModule.logger.warn).toHaveBeenCalledWith(expectedErrorMessage)
36+
it("should provide the commit", () => {
37+
// Source: https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39#gistcomment-2896416
38+
expect(commit).toBe("f6b2be2838f4afb217c2fd8f03eafedd8d55ef9b")
2739
})
2840

29-
it("should find the package.json", () => {
30-
// the function calls require from src/node/constants
31-
// so to get the root package.json we need to use ../../
32-
const packageJson = getPackageJson("../../package.json")
33-
expect(Object.keys(packageJson).length).toBeGreaterThan(0)
34-
expect(packageJson.name).toBe("code-server")
35-
expect(packageJson.description).toBe("Run VS Code on a remote server.")
36-
expect(packageJson.repository).toBe("https://github.com/cdr/code-server")
41+
it("should return the package.json version", () => {
42+
// Source: https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39#gistcomment-2896416
43+
const validSemVar = new RegExp("^(0|[1-9]d*).(0|[1-9]d*).(0|[1-9]d*)")
44+
const isValidSemVar = validSemVar.test(version)
45+
expect(version).not.toBe(null)
46+
expect(isValidSemVar).toBe(true)
47+
expect(version).toBe("1.0.0")
3748
})
38-
})
39-
describe("version", () => {
40-
describe("with package.json.version defined", () => {
41-
let mockPackageJson = {
42-
name: "mock-code-server",
43-
version: "1.0.0",
44-
}
45-
let version = ""
46-
47-
beforeEach(() => {
48-
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
49-
version = require("../../src/node/constants").version
50-
})
5149

52-
afterEach(() => {
53-
jest.resetAllMocks()
54-
jest.resetModules()
55-
})
50+
describe("getPackageJson", () => {
51+
it("should log a warning if package.json not found", () => {
52+
const expectedErrorMessage = "Cannot find module './package.json' from 'src/node/constants.ts'"
5653

57-
it("should return the package.json version", () => {
58-
// Source: https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39#gistcomment-2896416
59-
const validSemVar = new RegExp("^(0|[1-9]d*).(0|[1-9]d*).(0|[1-9]d*)")
60-
const isValidSemVar = validSemVar.test(version)
61-
expect(version).not.toBe(null)
62-
expect(isValidSemVar).toBe(true)
63-
expect(version).toBe("1.0.0")
64-
})
65-
})
66-
describe("with package.json.version missing", () => {
67-
let mockPackageJson = {
68-
name: "mock-code-server",
69-
}
70-
let version = ""
71-
72-
beforeEach(() => {
73-
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
74-
version = require("../../src/node/constants").version
75-
})
54+
getPackageJson("./package.json")
7655

77-
afterEach(() => {
78-
jest.resetAllMocks()
79-
jest.resetModules()
56+
expect(loggerModule.logger.warn).toHaveBeenCalled()
57+
expect(loggerModule.logger.warn).toHaveBeenCalledWith(expectedErrorMessage)
8058
})
8159

82-
it("should return 'development'", () => {
83-
expect(version).toBe("development")
60+
it("should find the package.json", () => {
61+
// the function calls require from src/node/constants
62+
// so to get the root package.json we need to use ../../
63+
const packageJson = getPackageJson("../../package.json")
64+
expect(Object.keys(packageJson).length).toBeGreaterThan(0)
65+
expect(packageJson.name).toBe("mock-code-server")
66+
expect(packageJson.description).toBe("Run VS Code on a remote server.")
67+
expect(packageJson.repository).toBe("https://github.com/cdr/code-server")
8468
})
8569
})
8670
})
87-
describe("commit", () => {
88-
describe("with package.json.commit defined", () => {
89-
let mockPackageJson = {
90-
name: "mock-code-server",
91-
commit: "f6b2be2838f4afb217c2fd8f03eafedd8d55ef9b",
92-
}
93-
let commit = ""
94-
95-
beforeEach(() => {
96-
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
97-
commit = require("../../src/node/constants").commit
98-
})
99-
100-
afterEach(() => {
101-
jest.resetAllMocks()
102-
jest.resetModules()
103-
})
10471

105-
it("should return the package.json.commit", () => {
106-
// Source: https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39#gistcomment-2896416
107-
expect(commit).toBe("f6b2be2838f4afb217c2fd8f03eafedd8d55ef9b")
108-
})
72+
describe("with incomplete package.json", () => {
73+
let mockPackageJson = {
74+
name: "mock-code-server",
75+
}
76+
let version = ""
77+
let commit = ""
78+
79+
beforeEach(() => {
80+
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
81+
version = require("../../src/node/constants").version
82+
commit = require("../../src/node/constants").commit
10983
})
110-
describe("with package.json.commit missing", () => {
111-
let mockPackageJson = {
112-
name: "mock-code-server",
113-
}
114-
let commit = ""
115-
116-
beforeEach(() => {
117-
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
118-
commit = require("../../src/node/constants").commit
119-
})
12084

121-
afterEach(() => {
122-
jest.resetAllMocks()
123-
jest.resetModules()
124-
})
85+
afterEach(() => {
86+
jest.clearAllMocks()
87+
jest.resetModules()
88+
})
12589

126-
it("should return 'development'", () => {
127-
expect(commit).toBe("development")
128-
})
90+
it("version should return 'development'", () => {
91+
expect(version).toBe("development")
92+
})
93+
it("commit should return 'development'", () => {
94+
expect(commit).toBe("development")
12995
})
13096
})
13197
})

0 commit comments

Comments
 (0)