refactor: tests from mocha to jest

This commit is contained in:
Joe Previte 2021-01-11 18:37:27 +00:00
parent cef7d42652
commit de7d0394ae
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
1 changed files with 17 additions and 24 deletions

View File

@ -31,8 +31,7 @@ describe("parser", () => {
} }
it("should parse nothing", () => { it("should parse nothing", () => {
expect(parse([])).toBe({ _: [] }) expect(parse([])).toStrictEqual({ _: [] }) })
})
it("should parse all available options", () => { it("should parse all available options", () => {
expect( expect(
@ -114,7 +113,7 @@ describe("parser", () => {
process.env.LOG_LEVEL = "debug" process.env.LOG_LEVEL = "debug"
const defaults = await setDefaults(args) const defaults = await setDefaults(args)
expect(defaults).toEqual({ expect(defaults).toStrictEqual({
...defaults, ...defaults,
_: [], _: [],
log: "debug", log: "debug",
@ -125,7 +124,7 @@ describe("parser", () => {
process.env.LOG_LEVEL = "trace" process.env.LOG_LEVEL = "trace"
const updated = await setDefaults(args) const updated = await setDefaults(args)
expect(updated).toBe( { expect(updated).toStrictEqual( {
...updated, ...updated,
_: [], _: [],
log: "trace", log: "trace",
@ -354,19 +353,16 @@ describe("cli", () => {
it("should use existing if inside code-server", async () => { it("should use existing if inside code-server", async () => {
process.env.VSCODE_IPC_HOOK_CLI = "test" process.env.VSCODE_IPC_HOOK_CLI = "test"
const shouldOpen = await shouldOpenInExistingInstance(args) expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
expect(shouldOpen).toStrictEqual("test")
args.port = 8081 args.port = 8081
args._.push("./file") args._.push("./file")
const _shouldOpen = await shouldOpenInExistingInstance(args) expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
expect(_shouldOpen).toStrictEqual("test")
}) })
it("should use existing if --reuse-window is set", async () => { it("should use existing if --reuse-window is set", async () => {
args["reuse-window"] = true args["reuse-window"] = true
const shouldOpen = await shouldOpenInExistingInstance(args) await expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
await expect(shouldOpen).toStrictEqual(undefined)
await fs.writeFile(vscodeIpcPath, "test") await fs.writeFile(vscodeIpcPath, "test")
await expect(shouldOpenInExistingInstance(args)).resolves.toStrictEqual("test") await expect(shouldOpenInExistingInstance(args)).resolves.toStrictEqual("test")
@ -375,31 +371,28 @@ describe("cli", () => {
await expect(shouldOpenInExistingInstance(args)).resolves.toStrictEqual("test") await expect(shouldOpenInExistingInstance(args)).resolves.toStrictEqual("test")
}) })
// TODO
// fix red squiggles
// and don't use should Open on all these
it("should use existing if --new-window is set", async () => { it("should use existing if --new-window is set", async () => {
args["new-window"] = true args["new-window"] = true
expect(await shouldOpenInExistingInstance(args).toStrictEqual(undefined) expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
await fs.writeFile(vscodeIpcPath, "test") await fs.writeFile(vscodeIpcPath, "test")
expect(await shouldOpenInExistingInstance(args).toStrictEqual("test") expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
args.port = 8081 args.port = 8081
expect(await shouldOpenInExistingInstance(args).toStrictEqual("test") expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
}) })
it( it(
"should use existing if no unrelated flags are set, has positional, and socket is active", "should use existing if no unrelated flags are set, has positional, and socket is active",
async () => { async () => {
expect(await shouldOpenInExistingInstance(args).toStrictEqual(undefined) expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
args._.push("./file") args._.push("./file")
expect(await shouldOpenInExistingInstance(args).toStrictEqual(undefined) expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
const socketPath = path.join(testDir, "socket") const socketPath = path.join(testDir, "socket")
await fs.writeFile(vscodeIpcPath, socketPath) await fs.writeFile(vscodeIpcPath, socketPath)
expect(await shouldOpenInExistingInstance(args).toStrictEqual(undefined) expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
await new Promise((resolve) => { await new Promise((resolve) => {
const server = net.createServer(() => { const server = net.createServer(() => {
@ -410,10 +403,10 @@ describe("cli", () => {
server.listen(socketPath) server.listen(socketPath)
}) })
expect(await shouldOpenInExistingInstance(args).toStrictEqual(socketPath) expect(await shouldOpenInExistingInstance(args)).toStrictEqual(socketPath)
args.port = 8081 args.port = 8081
expect(await shouldOpenInExistingInstance(args).toStrictEqual(undefined) expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
} }
) )
}) })