Skip to content

Commit a1e4e9d

Browse files
committed
fix: prevent mocha/jest types conlict
Modify the tsconfig.json in lib/vscode/src/build. This adds the flag skipLibCheck: true to tell TypeScript to not type-check the declaration files at build time. We need to add this because otherwise it checks the declaration files and reports an error of duplicate type definitions because we use Jest for our tests and they use Mocha and they both use the global namespace "test" in their .d.ts files.
1 parent 6e2d09c commit a1e4e9d

File tree

6 files changed

+117
-477
lines changed

6 files changed

+117
-477
lines changed

jest.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
preset: 'ts-jest',
3-
testEnvironment: 'node',
4-
testPathIgnorePatterns: ["/node_modules/", "lib/vscode/"]
5-
};
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
testPathIgnorePatterns: ["/node_modules/", "lib/vscode/"],
5+
}

lib/vscode/build/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"strict": true,
1616
"noUnusedLocals": true,
1717
"noUnusedParameters": true,
18-
"newLine": "lf"
18+
"newLine": "lf",
19+
"skipLibCheck": true
1920
},
2021
"include": [
2122
"**/*.ts"

test/cli.test.ts

+75-81
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ describe("parser", () => {
3131
}
3232

3333
it("should parse nothing", () => {
34-
expect(parse([])).toStrictEqual({ _: [] }) })
34+
expect(parse([])).toStrictEqual({ _: [] })
35+
})
3536

3637
it("should parse all available options", () => {
3738
expect(
@@ -71,32 +72,31 @@ describe("parser", () => {
7172
"--",
7273
"-5",
7374
"--6",
74-
])).toEqual(
75-
{
76-
_: ["1", "2", "3", "4", "-5", "--6"],
77-
auth: "none",
78-
"builtin-extensions-dir": path.resolve("foobar"),
79-
"cert-key": path.resolve("qux"),
80-
cert: {
81-
value: path.resolve("baz"),
82-
},
83-
"extensions-dir": path.resolve("foo"),
84-
"extra-builtin-extensions-dir": [path.resolve("bazzle")],
85-
"extra-extensions-dir": [path.resolve("nozzle")],
86-
help: true,
87-
home: "http://localhost:8080/",
88-
host: "0.0.0.0",
89-
json: true,
90-
log: "error",
91-
open: true,
92-
port: 8081,
93-
socket: path.resolve("mumble"),
94-
"user-data-dir": path.resolve("bar"),
95-
verbose: true,
96-
version: true,
97-
"bind-addr": "192.169.0.1:8080",
75+
]),
76+
).toEqual({
77+
_: ["1", "2", "3", "4", "-5", "--6"],
78+
auth: "none",
79+
"builtin-extensions-dir": path.resolve("foobar"),
80+
"cert-key": path.resolve("qux"),
81+
cert: {
82+
value: path.resolve("baz"),
9883
},
99-
)
84+
"extensions-dir": path.resolve("foo"),
85+
"extra-builtin-extensions-dir": [path.resolve("bazzle")],
86+
"extra-extensions-dir": [path.resolve("nozzle")],
87+
help: true,
88+
home: "http://localhost:8080/",
89+
host: "0.0.0.0",
90+
json: true,
91+
log: "error",
92+
open: true,
93+
port: 8081,
94+
socket: path.resolve("mumble"),
95+
"user-data-dir": path.resolve("bar"),
96+
verbose: true,
97+
version: true,
98+
"bind-addr": "192.169.0.1:8080",
99+
})
100100
})
101101

102102
it("should work with short options", () => {
@@ -124,7 +124,7 @@ describe("parser", () => {
124124

125125
process.env.LOG_LEVEL = "trace"
126126
const updated = await setDefaults(args)
127-
expect(updated).toStrictEqual( {
127+
expect(updated).toStrictEqual({
128128
...updated,
129129
_: [],
130130
log: "trace",
@@ -142,7 +142,7 @@ describe("parser", () => {
142142
})
143143

144144
process.env.LOG_LEVEL = "debug"
145-
const defaults = await setDefaults(args)
145+
const defaults = await setDefaults(args)
146146
expect(defaults).toEqual({
147147
...defaults,
148148
_: [],
@@ -154,7 +154,7 @@ describe("parser", () => {
154154

155155
process.env.LOG_LEVEL = "trace"
156156
const updated = await setDefaults(args)
157-
expect(updated).toEqual( {
157+
expect(updated).toEqual({
158158
...defaults,
159159
_: [],
160160
log: "info",
@@ -172,7 +172,7 @@ describe("parser", () => {
172172

173173
process.env.LOG_LEVEL = "warn"
174174
const updatedAgain = await setDefaults(args)
175-
expect(updatedAgain).toEqual( {
175+
expect(updatedAgain).toEqual({
176176
...defaults,
177177
_: [],
178178
log: "trace",
@@ -206,7 +206,7 @@ describe("parser", () => {
206206
})
207207

208208
it("should error if the option doesn't exist", () => {
209-
expect(()=> parse(["--foo"])).toThrowError(/Unknown option --foo/)
209+
expect(() => parse(["--foo"])).toThrowError(/Unknown option --foo/)
210210
})
211211

212212
it("should not error if the value is optional", () => {
@@ -246,28 +246,25 @@ describe("parser", () => {
246246
})
247247
})
248248

249-
it(
250-
"should enforce cert-key with cert value or otherwise generate one",
251-
async () => {
252-
const args = parse(["--cert"])
253-
expect(args).toEqual( {
254-
_: [],
255-
cert: {
256-
value: undefined,
257-
},
258-
})
259-
expect(() => parse(["--cert", "test"])).toThrowError(/--cert-key is missing/)
260-
const defaultArgs = await setDefaults(args)
261-
expect(defaultArgs).toEqual({
262-
_: [],
263-
...defaults,
264-
cert: {
265-
value: path.join(paths.data, "localhost.crt"),
266-
},
267-
"cert-key": path.join(paths.data, "localhost.key"),
268-
})
269-
}
270-
)
249+
it("should enforce cert-key with cert value or otherwise generate one", async () => {
250+
const args = parse(["--cert"])
251+
expect(args).toEqual({
252+
_: [],
253+
cert: {
254+
value: undefined,
255+
},
256+
})
257+
expect(() => parse(["--cert", "test"])).toThrowError(/--cert-key is missing/)
258+
const defaultArgs = await setDefaults(args)
259+
expect(defaultArgs).toEqual({
260+
_: [],
261+
...defaults,
262+
cert: {
263+
value: path.join(paths.data, "localhost.crt"),
264+
},
265+
"cert-key": path.join(paths.data, "localhost.key"),
266+
})
267+
})
271268

272269
it("should override with --link", async () => {
273270
const args = parse("--cert test --cert-key test --socket test --host 0.0.0.0 --port 8888 --link test".split(" "))
@@ -310,7 +307,7 @@ describe("parser", () => {
310307
_: [],
311308
})
312309

313-
const defaultArgs = await setDefaults(args)
310+
const defaultArgs = await setDefaults(args)
314311
expect(defaultArgs).toEqual({
315312
...defaults,
316313
_: [],
@@ -352,11 +349,11 @@ describe("cli", () => {
352349
})
353350

354351
it("should use existing if inside code-server", async () => {
355-
process.env.VSCODE_IPC_HOOK_CLI = "test"
352+
process.env.VSCODE_IPC_HOOK_CLI = "test"
356353
expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
357354

358355
args.port = 8081
359-
args._.push("./file")
356+
args._.push("./file")
360357
expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
361358
})
362359

@@ -370,7 +367,7 @@ describe("cli", () => {
370367
args.port = 8081
371368
await expect(shouldOpenInExistingInstance(args)).resolves.toStrictEqual("test")
372369
})
373-
370+
374371
it("should use existing if --new-window is set", async () => {
375372
args["new-window"] = true
376373
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
@@ -382,31 +379,28 @@ describe("cli", () => {
382379
expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
383380
})
384381

385-
it(
386-
"should use existing if no unrelated flags are set, has positional, and socket is active",
387-
async () => {
388-
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
389-
390-
args._.push("./file")
391-
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
392-
393-
const socketPath = path.join(testDir, "socket")
394-
await fs.writeFile(vscodeIpcPath, socketPath)
395-
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
396-
397-
await new Promise((resolve) => {
398-
const server = net.createServer(() => {
399-
// Close after getting the first connection.
400-
server.close()
401-
})
402-
server.once("listening", () => resolve(server))
403-
server.listen(socketPath)
382+
it("should use existing if no unrelated flags are set, has positional, and socket is active", async () => {
383+
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
384+
385+
args._.push("./file")
386+
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
387+
388+
const socketPath = path.join(testDir, "socket")
389+
await fs.writeFile(vscodeIpcPath, socketPath)
390+
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
391+
392+
await new Promise((resolve) => {
393+
const server = net.createServer(() => {
394+
// Close after getting the first connection.
395+
server.close()
404396
})
397+
server.once("listening", () => resolve(server))
398+
server.listen(socketPath)
399+
})
405400

406-
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(socketPath)
401+
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(socketPath)
407402

408-
args.port = 8081
409-
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
410-
}
411-
)
403+
args.port = 8081
404+
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
405+
})
412406
})

test/plugin.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("plugin", () => {
2020
await papi.loadPlugins()
2121

2222
app = express.default()
23-
papi.mount(app)
23+
papi.mount(app)
2424

2525
app.use("/api/applications", apps.router(papi))
2626

test/socket.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { field, logger } from "@coder/logger"
1+
import { field, logger } from "@coder/logger"
22
import * as fs from "fs-extra"
33
import "leaked-handles"
44
import * as net from "net"
@@ -125,4 +125,3 @@ describe("SocketProxyProvider", () => {
125125
proxy.end()
126126
})
127127
})
128-

0 commit comments

Comments
 (0)