Skip to content

Commit f45cc1c

Browse files
committed
chore: prettier
1 parent c62af04 commit f45cc1c

File tree

2 files changed

+96
-96
lines changed

2 files changed

+96
-96
lines changed

test/utils/platform.test.ts

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as cp from "node:child_process";
2-
import fs from "node:fs/promises";
3-
import os from "node:os";
4-
import path from "node:path";
5-
import {beforeAll, describe, expect, it} from "vitest";
1+
import * as cp from "node:child_process"
2+
import fs from "node:fs/promises"
3+
import os from "node:os"
4+
import path from "node:path"
5+
import { beforeAll, describe, expect, it } from "vitest"
66

77
import {
88
expectPathsEqual,
@@ -12,154 +12,152 @@ import {
1212
printEnvCommand,
1313
shimExecFile,
1414
writeExecutable,
15-
} from "./platform";
15+
} from "./platform"
1616

1717
describe("platform utils", () => {
1818
describe("printCommand", () => {
1919
it("should generate a simple node command", () => {
20-
const result = printCommand("hello world");
21-
expect(result).toBe("node -e \"process.stdout.write('hello world')\"");
22-
});
20+
const result = printCommand("hello world")
21+
expect(result).toBe("node -e \"process.stdout.write('hello world')\"")
22+
})
2323

2424
it("should escape special characters", () => {
25-
const result = printCommand('path\\to\\file\'s "name"\nline2\rcarriage');
25+
const result = printCommand('path\\to\\file\'s "name"\nline2\rcarriage')
2626
expect(result).toBe(
2727
'node -e "process.stdout.write(\'path\\\\to\\\\file\\\'s \\"name\\"\\nline2\\rcarriage\')"',
28-
);
29-
});
30-
});
28+
)
29+
})
30+
})
3131

3232
describe("exitCommand", () => {
3333
it("should generate node commands with various exit codes", () => {
34-
expect(exitCommand(0)).toBe('node -e "process.exit(0)"');
35-
expect(exitCommand(1)).toBe('node -e "process.exit(1)"');
36-
expect(exitCommand(42)).toBe('node -e "process.exit(42)"');
37-
expect(exitCommand(-1)).toBe('node -e "process.exit(-1)"');
38-
});
39-
});
34+
expect(exitCommand(0)).toBe('node -e "process.exit(0)"')
35+
expect(exitCommand(1)).toBe('node -e "process.exit(1)"')
36+
expect(exitCommand(42)).toBe('node -e "process.exit(42)"')
37+
expect(exitCommand(-1)).toBe('node -e "process.exit(-1)"')
38+
})
39+
})
4040

4141
describe("printEnvCommand", () => {
4242
it("should generate node commands that print env variables", () => {
4343
expect(printEnvCommand("url", "CODER_URL")).toBe(
4444
"node -e \"process.stdout.write('url=' + process.env.CODER_URL)\"",
45-
);
45+
)
4646
expect(printEnvCommand("token", "CODER_TOKEN")).toBe(
4747
"node -e \"process.stdout.write('token=' + process.env.CODER_TOKEN)\"",
48-
);
48+
)
4949
// Will fail to execute but that's fine
5050
expect(printEnvCommand("", "")).toBe(
5151
"node -e \"process.stdout.write('=' + process.env.)\"",
52-
);
53-
});
54-
});
52+
)
53+
})
54+
})
5555

5656
describe("expectPathsEqual", () => {
5757
it("should consider identical paths equal", () => {
58-
expectPathsEqual("same/path", "same/path");
59-
});
58+
expectPathsEqual("same/path", "same/path")
59+
})
6060

6161
it("should throw when paths are different", () => {
62-
expect(() =>
63-
expectPathsEqual("path/to/file1", "path/to/file2"),
64-
).toThrow();
65-
});
62+
expect(() => expectPathsEqual("path/to/file1", "path/to/file2")).toThrow()
63+
})
6664

6765
it("should handle empty paths", () => {
68-
expectPathsEqual("", "");
69-
});
66+
expectPathsEqual("", "")
67+
})
7068

7169
it.runIf(isWindows())(
7270
"should consider paths with different separators equal on Windows",
7371
() => {
74-
expectPathsEqual("path/to/file", "path\\to\\file");
75-
expectPathsEqual("C:/path/to/file", "C:\\path\\to\\file");
72+
expectPathsEqual("path/to/file", "path\\to\\file")
73+
expectPathsEqual("C:/path/to/file", "C:\\path\\to\\file")
7674
expectPathsEqual(
7775
"C:/path with spaces/file",
7876
"C:\\path with spaces\\file",
79-
);
77+
)
8078
},
81-
);
79+
)
8280

8381
it.skipIf(isWindows())(
8482
"should consider backslash as literal on non-Windows",
8583
() => {
8684
expect(() =>
8785
expectPathsEqual("path/to/file", "path\\to\\file"),
88-
).toThrow();
86+
).toThrow()
8987
},
90-
);
91-
});
88+
)
89+
})
9290

9391
describe("writeExecutable", () => {
94-
const tmp = path.join(os.tmpdir(), "vscode-coder-tests-platform");
92+
const tmp = path.join(os.tmpdir(), "vscode-coder-tests-platform")
9593

9694
beforeAll(async () => {
97-
await fs.rm(tmp, {recursive: true, force: true});
98-
await fs.mkdir(tmp, {recursive: true});
99-
});
95+
await fs.rm(tmp, { recursive: true, force: true })
96+
await fs.mkdir(tmp, { recursive: true })
97+
})
10098

10199
it("writes a .js file and returns its path", async () => {
102-
const result = await writeExecutable(tmp, "test-script", "// hello");
103-
expect(result).toBe(path.join(tmp, "test-script.js"));
104-
expect(await fs.readFile(result, "utf-8")).toBe("// hello");
105-
});
100+
const result = await writeExecutable(tmp, "test-script", "// hello")
101+
expect(result).toBe(path.join(tmp, "test-script.js"))
102+
expect(await fs.readFile(result, "utf-8")).toBe("// hello")
103+
})
106104

107105
it("overwrites existing files", async () => {
108-
await writeExecutable(tmp, "overwrite", "first");
109-
const result = await writeExecutable(tmp, "overwrite", "second");
110-
expect(await fs.readFile(result, "utf-8")).toBe("second");
111-
});
112-
});
106+
await writeExecutable(tmp, "overwrite", "first")
107+
const result = await writeExecutable(tmp, "overwrite", "second")
108+
expect(await fs.readFile(result, "utf-8")).toBe("second")
109+
})
110+
})
113111

114112
describe("shimExecFile", () => {
115-
const tmp = path.join(os.tmpdir(), "vscode-coder-tests-shim");
116-
const mod = shimExecFile(cp);
113+
const tmp = path.join(os.tmpdir(), "vscode-coder-tests-shim")
114+
const mod = shimExecFile(cp)
117115

118116
beforeAll(async () => {
119-
await fs.rm(tmp, {recursive: true, force: true});
120-
await fs.mkdir(tmp, {recursive: true});
121-
});
117+
await fs.rm(tmp, { recursive: true, force: true })
118+
await fs.mkdir(tmp, { recursive: true })
119+
})
122120

123121
it("runs .js files through node", async () => {
124122
const script = await writeExecutable(
125123
tmp,
126124
"echo",
127125
'process.stdout.write("ok");',
128-
);
126+
)
129127
const stdout = await new Promise<string>((resolve, reject) => {
130128
mod.execFile(script, (err, out) =>
131129
err ? reject(new Error(err.message)) : resolve(out),
132-
);
133-
});
134-
expect(stdout).toBe("ok");
135-
});
130+
)
131+
})
132+
expect(stdout).toBe("ok")
133+
})
136134

137135
it("passes args through to the script", async () => {
138136
const script = await writeExecutable(
139137
tmp,
140138
"echo-args",
141139
"process.stdout.write(process.argv.slice(2).join(','));",
142-
);
140+
)
143141
const stdout = await new Promise<string>((resolve, reject) => {
144142
mod.execFile(script, ["a", "b", "c"], (err, out) =>
145143
err ? reject(new Error(err.message)) : resolve(out),
146-
);
147-
});
148-
expect(stdout).toBe("a,b,c");
149-
});
144+
)
145+
})
146+
expect(stdout).toBe("a,b,c")
147+
})
150148

151149
it("does not rewrite non-.js files", async () => {
152150
await expect(
153151
new Promise((resolve, reject) => {
154152
mod.execFile("/nonexistent/binary", (err, out) =>
155153
err ? reject(new Error(err.message)) : resolve(out),
156-
);
154+
)
157155
}),
158-
).rejects.toThrow("ENOENT");
159-
});
156+
).rejects.toThrow("ENOENT")
157+
})
160158

161159
it("does not touch spawn", () => {
162-
expect(mod.spawn).toBe(cp.spawn);
163-
});
164-
});
165-
});
160+
expect(mod.spawn).toBe(cp.spawn)
161+
})
162+
})
163+
})

test/utils/platform.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import fs from "node:fs/promises";
2-
import os from "node:os";
3-
import path from "node:path";
4-
import {expect} from "vitest";
1+
import fs from "node:fs/promises"
2+
import os from "node:os"
3+
import path from "node:path"
4+
import { expect } from "vitest"
55

6-
import type * as cp from "node:child_process";
6+
import type * as cp from "node:child_process"
77

88
export function isWindows(): boolean {
9-
return os.platform() === "win32";
9+
return os.platform() === "win32"
1010
}
1111

1212
/**
@@ -19,16 +19,16 @@ export function printCommand(output: string): string {
1919
.replace(/'/g, "\\'") // Escape single quotes
2020
.replace(/"/g, '\\"') // Escape double quotes
2121
.replace(/\r/g, "\\r") // Preserve carriage returns
22-
.replace(/\n/g, "\\n"); // Preserve newlines
22+
.replace(/\n/g, "\\n") // Preserve newlines
2323

24-
return `node -e "process.stdout.write('${escaped}')"`;
24+
return `node -e "process.stdout.write('${escaped}')"`
2525
}
2626

2727
/**
2828
* Returns a platform-independent command that exits with the given code.
2929
*/
3030
export function exitCommand(code: number): string {
31-
return `node -e "process.exit(${code})"`;
31+
return `node -e "process.exit(${code})"`
3232
}
3333

3434
/**
@@ -37,7 +37,7 @@ export function exitCommand(code: number): string {
3737
* @param varName The environment variable name to access
3838
*/
3939
export function printEnvCommand(key: string, varName: string): string {
40-
return `node -e "process.stdout.write('${key}=' + process.env.${varName})"`;
40+
return `node -e "process.stdout.write('${key}=' + process.env.${varName})"`
4141
}
4242

4343
/**
@@ -50,9 +50,9 @@ export async function writeExecutable(
5050
name: string,
5151
code: string,
5252
): Promise<string> {
53-
const jsPath = path.join(dir, `${name}.js`);
54-
await fs.writeFile(jsPath, code);
55-
return jsPath;
53+
const jsPath = path.join(dir, `${name}.js`)
54+
await fs.writeFile(jsPath, code)
55+
return jsPath
5656
}
5757

5858
/**
@@ -61,11 +61,11 @@ export async function writeExecutable(
6161
* (Windows cannot `execFile` script wrappers).
6262
*/
6363
function prepend(file: string, rest: unknown[]): [string, ...unknown[]] {
64-
if (!file.endsWith(".js")) return [file, ...rest];
64+
if (!file.endsWith(".js")) return [file, ...rest]
6565
if (Array.isArray(rest[0])) {
66-
return [process.execPath, [file, ...rest[0]], ...rest.slice(1)];
66+
return [process.execPath, [file, ...rest[0]], ...rest.slice(1)]
6767
}
68-
return [process.execPath, [file], ...rest];
68+
return [process.execPath, [file], ...rest]
6969
}
7070

7171
/**
@@ -79,20 +79,22 @@ function prepend(file: string, rest: unknown[]): [string, ...unknown[]] {
7979
* });
8080
* ```
8181
*/
82-
export function shimExecFile<M extends {execFile: (...args: never[]) => unknown}>(mod: M): M {
83-
const {execFile: original} = mod;
82+
export function shimExecFile<
83+
M extends { execFile: (...args: never[]) => unknown },
84+
>(mod: M): M {
85+
const { execFile: original } = mod
8486

8587
function execFile(file: string, ...rest: unknown[]): cp.ChildProcess {
86-
return Reflect.apply(original, undefined, prepend(file, rest));
88+
return Reflect.apply(original, undefined, prepend(file, rest))
8789
}
8890

89-
return Object.assign({}, mod, {execFile});
91+
return Object.assign({}, mod, { execFile })
9092
}
9193

9294
export function expectPathsEqual(actual: string, expected: string) {
93-
expect(normalizePath(actual)).toBe(normalizePath(expected));
95+
expect(normalizePath(actual)).toBe(normalizePath(expected))
9496
}
9597

9698
function normalizePath(p: string): string {
97-
return p.replaceAll(path.sep, path.posix.sep);
99+
return p.replaceAll(path.sep, path.posix.sep)
98100
}

0 commit comments

Comments
 (0)