chore: switch codebase to use TS strict mode

pull/273/head
Parkreiner 10 months ago
parent f7fa145855
commit cd010baac8

@ -126,7 +126,10 @@ const assertSlackMessage = async (opts: {
durationMS?: number;
output: string;
}) => {
let url: URL;
// Have to use non-null assertion because TS can't tell when the fetch
// function will run
let url!: URL;
const fakeSlackHost = serve({
fetch: (req) => {
url = new URL(req.url);
@ -138,15 +141,16 @@ const assertSlackMessage = async (opts: {
},
port: 0,
});
const { instance, id } = await setupContainer(
"alpine/curl",
opts.format && {
slack_message: opts.format,
},
opts.format ? { slack_message: opts.format } : undefined,
);
await writeCoder(id, "echo 'token'");
let exec = await execContainer(id, ["sh", "-c", instance.script]);
expect(exec.exitCode).toBe(0);
exec = await execContainer(id, [
"sh",
"-c",
@ -154,6 +158,7 @@ const assertSlackMessage = async (opts: {
fakeSlackHost.hostname
}:${fakeSlackHost.port}" slackme ${opts.command}`,
]);
expect(exec.stderr.trim()).toBe("");
expect(url.pathname).toEqual("/api/chat.postMessage");
expect(url.searchParams.get("channel")).toEqual("token");

@ -149,19 +149,25 @@ export const testRequiredVariables = <TVars extends Record<string, string>>(
it("required variables", async () => {
await runTerraformApply(dir, vars);
});
const varNames = Object.keys(vars);
varNames.forEach((varName) => {
// Ensures that every variable provided is required!
it("missing variable " + varName, async () => {
const localVars = {};
const localVars: Record<string, string> = {};
varNames.forEach((otherVarName) => {
if (otherVarName !== varName) {
localVars[otherVarName] = vars[otherVarName];
}
});
try {
await runTerraformApply(dir, localVars);
} catch (ex) {
if (!(ex instanceof Error)) {
throw new Error("Unknown error generated");
}
expect(ex.message).toContain(
`input variable \"${varName}\" is not set`,
);

@ -2,6 +2,7 @@
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "nodenext",
"types": ["bun-types"]

@ -24,9 +24,10 @@ describe("vscode-desktop", async () => {
const coder_app = state.resources.find(
(res) => res.type == "coder_app" && res.name == "vscode",
);
expect(coder_app).not.toBeNull();
expect(coder_app.instances.length).toBe(1);
expect(coder_app.instances[0].attributes.order).toBeNull();
expect(coder_app?.instances.length).toBe(1);
expect(coder_app?.instances[0].attributes.order).toBeNull();
});
it("adds folder", async () => {
@ -80,8 +81,9 @@ describe("vscode-desktop", async () => {
const coder_app = state.resources.find(
(res) => res.type == "coder_app" && res.name == "vscode",
);
expect(coder_app).not.toBeNull();
expect(coder_app.instances.length).toBe(1);
expect(coder_app.instances[0].attributes.order).toBe(22);
expect(coder_app?.instances.length).toBe(1);
expect(coder_app?.instances[0].attributes.order).toBe(22);
});
});

@ -99,11 +99,11 @@ describe("Web RDP", async () => {
const defaultRdpScript = findWindowsRdpScript(defaultState);
expect(defaultRdpScript).toBeString();
const { username: defaultUsername, password: defaultPassword } =
formEntryValuesRe.exec(defaultRdpScript)?.groups ?? {};
const defaultResultsGroup =
formEntryValuesRe.exec(defaultRdpScript ?? "")?.groups ?? {};
expect(defaultUsername).toBe("Administrator");
expect(defaultPassword).toBe("coderRDP!");
expect(defaultResultsGroup.username).toBe("Administrator");
expect(defaultResultsGroup.password).toBe("coderRDP!");
// Test that custom usernames/passwords are also forwarded correctly
const customAdminUsername = "crouton";
@ -121,10 +121,10 @@ describe("Web RDP", async () => {
const customRdpScript = findWindowsRdpScript(customizedState);
expect(customRdpScript).toBeString();
const { username: customUsername, password: customPassword } =
formEntryValuesRe.exec(customRdpScript)?.groups ?? {};
const customResultsGroup =
formEntryValuesRe.exec(customRdpScript ?? "")?.groups ?? {};
expect(customUsername).toBe(customAdminUsername);
expect(customPassword).toBe(customAdminPassword);
expect(customResultsGroup.username).toBe(customAdminUsername);
expect(customResultsGroup.password).toBe(customAdminPassword);
});
});

Loading…
Cancel
Save