Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit cd010ba

Browse files
committed
chore: switch codebase to use TS strict mode
1 parent f7fa145 commit cd010ba

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

slackme/main.test.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ const assertSlackMessage = async (opts: {
126126
durationMS?: number;
127127
output: string;
128128
}) => {
129-
let url: URL;
129+
// Have to use non-null assertion because TS can't tell when the fetch
130+
// function will run
131+
let url!: URL;
132+
130133
const fakeSlackHost = serve({
131134
fetch: (req) => {
132135
url = new URL(req.url);
@@ -138,22 +141,24 @@ const assertSlackMessage = async (opts: {
138141
},
139142
port: 0,
140143
});
144+
141145
const { instance, id } = await setupContainer(
142146
"alpine/curl",
143-
opts.format && {
144-
slack_message: opts.format,
145-
},
147+
opts.format ? { slack_message: opts.format } : undefined,
146148
);
149+
147150
await writeCoder(id, "echo 'token'");
148151
let exec = await execContainer(id, ["sh", "-c", instance.script]);
149152
expect(exec.exitCode).toBe(0);
153+
150154
exec = await execContainer(id, [
151155
"sh",
152156
"-c",
153157
`DURATION_MS=${opts.durationMS || 0} SLACK_URL="http://${
154158
fakeSlackHost.hostname
155159
}:${fakeSlackHost.port}" slackme ${opts.command}`,
156160
]);
161+
157162
expect(exec.stderr.trim()).toBe("");
158163
expect(url.pathname).toEqual("/api/chat.postMessage");
159164
expect(url.searchParams.get("channel")).toEqual("token");

test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,25 @@ export const testRequiredVariables = <TVars extends Record<string, string>>(
149149
it("required variables", async () => {
150150
await runTerraformApply(dir, vars);
151151
});
152+
152153
const varNames = Object.keys(vars);
153154
varNames.forEach((varName) => {
154155
// Ensures that every variable provided is required!
155156
it("missing variable " + varName, async () => {
156-
const localVars = {};
157+
const localVars: Record<string, string> = {};
157158
varNames.forEach((otherVarName) => {
158159
if (otherVarName !== varName) {
159160
localVars[otherVarName] = vars[otherVarName];
160161
}
161162
});
163+
162164
try {
163165
await runTerraformApply(dir, localVars);
164166
} catch (ex) {
167+
if (!(ex instanceof Error)) {
168+
throw new Error("Unknown error generated");
169+
}
170+
165171
expect(ex.message).toContain(
166172
`input variable \"${varName}\" is not set`,
167173
);

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"target": "esnext",
44
"module": "esnext",
5+
"strict": true,
56
"allowSyntheticDefaultImports": true,
67
"moduleResolution": "nodenext",
78
"types": ["bun-types"]

vscode-desktop/main.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ describe("vscode-desktop", async () => {
2424
const coder_app = state.resources.find(
2525
(res) => res.type == "coder_app" && res.name == "vscode",
2626
);
27+
2728
expect(coder_app).not.toBeNull();
28-
expect(coder_app.instances.length).toBe(1);
29-
expect(coder_app.instances[0].attributes.order).toBeNull();
29+
expect(coder_app?.instances.length).toBe(1);
30+
expect(coder_app?.instances[0].attributes.order).toBeNull();
3031
});
3132

3233
it("adds folder", async () => {
@@ -80,8 +81,9 @@ describe("vscode-desktop", async () => {
8081
const coder_app = state.resources.find(
8182
(res) => res.type == "coder_app" && res.name == "vscode",
8283
);
84+
8385
expect(coder_app).not.toBeNull();
84-
expect(coder_app.instances.length).toBe(1);
85-
expect(coder_app.instances[0].attributes.order).toBe(22);
86+
expect(coder_app?.instances.length).toBe(1);
87+
expect(coder_app?.instances[0].attributes.order).toBe(22);
8688
});
8789
});

windows-rdp/main.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ describe("Web RDP", async () => {
9999
const defaultRdpScript = findWindowsRdpScript(defaultState);
100100
expect(defaultRdpScript).toBeString();
101101

102-
const { username: defaultUsername, password: defaultPassword } =
103-
formEntryValuesRe.exec(defaultRdpScript)?.groups ?? {};
102+
const defaultResultsGroup =
103+
formEntryValuesRe.exec(defaultRdpScript ?? "")?.groups ?? {};
104104

105-
expect(defaultUsername).toBe("Administrator");
106-
expect(defaultPassword).toBe("coderRDP!");
105+
expect(defaultResultsGroup.username).toBe("Administrator");
106+
expect(defaultResultsGroup.password).toBe("coderRDP!");
107107

108108
// Test that custom usernames/passwords are also forwarded correctly
109109
const customAdminUsername = "crouton";
@@ -121,10 +121,10 @@ describe("Web RDP", async () => {
121121
const customRdpScript = findWindowsRdpScript(customizedState);
122122
expect(customRdpScript).toBeString();
123123

124-
const { username: customUsername, password: customPassword } =
125-
formEntryValuesRe.exec(customRdpScript)?.groups ?? {};
124+
const customResultsGroup =
125+
formEntryValuesRe.exec(customRdpScript ?? "")?.groups ?? {};
126126

127-
expect(customUsername).toBe(customAdminUsername);
128-
expect(customPassword).toBe(customAdminPassword);
127+
expect(customResultsGroup.username).toBe(customAdminUsername);
128+
expect(customResultsGroup.password).toBe(customAdminPassword);
129129
});
130130
});

0 commit comments

Comments
 (0)