chore: switch codebase to use TS strict mode
This commit is contained in:
@@ -126,7 +126,10 @@ const assertSlackMessage = async (opts: {
|
|||||||
durationMS?: number;
|
durationMS?: number;
|
||||||
output: string;
|
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({
|
const fakeSlackHost = serve({
|
||||||
fetch: (req) => {
|
fetch: (req) => {
|
||||||
url = new URL(req.url);
|
url = new URL(req.url);
|
||||||
@@ -138,15 +141,16 @@ const assertSlackMessage = async (opts: {
|
|||||||
},
|
},
|
||||||
port: 0,
|
port: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { instance, id } = await setupContainer(
|
const { instance, id } = await setupContainer(
|
||||||
"alpine/curl",
|
"alpine/curl",
|
||||||
opts.format && {
|
opts.format ? { slack_message: opts.format } : undefined,
|
||||||
slack_message: opts.format,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await writeCoder(id, "echo 'token'");
|
await writeCoder(id, "echo 'token'");
|
||||||
let exec = await execContainer(id, ["sh", "-c", instance.script]);
|
let exec = await execContainer(id, ["sh", "-c", instance.script]);
|
||||||
expect(exec.exitCode).toBe(0);
|
expect(exec.exitCode).toBe(0);
|
||||||
|
|
||||||
exec = await execContainer(id, [
|
exec = await execContainer(id, [
|
||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-c",
|
||||||
@@ -154,6 +158,7 @@ const assertSlackMessage = async (opts: {
|
|||||||
fakeSlackHost.hostname
|
fakeSlackHost.hostname
|
||||||
}:${fakeSlackHost.port}" slackme ${opts.command}`,
|
}:${fakeSlackHost.port}" slackme ${opts.command}`,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(exec.stderr.trim()).toBe("");
|
expect(exec.stderr.trim()).toBe("");
|
||||||
expect(url.pathname).toEqual("/api/chat.postMessage");
|
expect(url.pathname).toEqual("/api/chat.postMessage");
|
||||||
expect(url.searchParams.get("channel")).toEqual("token");
|
expect(url.searchParams.get("channel")).toEqual("token");
|
||||||
|
|||||||
8
test.ts
8
test.ts
@@ -149,19 +149,25 @@ export const testRequiredVariables = <TVars extends Record<string, string>>(
|
|||||||
it("required variables", async () => {
|
it("required variables", async () => {
|
||||||
await runTerraformApply(dir, vars);
|
await runTerraformApply(dir, vars);
|
||||||
});
|
});
|
||||||
|
|
||||||
const varNames = Object.keys(vars);
|
const varNames = Object.keys(vars);
|
||||||
varNames.forEach((varName) => {
|
varNames.forEach((varName) => {
|
||||||
// Ensures that every variable provided is required!
|
// Ensures that every variable provided is required!
|
||||||
it("missing variable " + varName, async () => {
|
it("missing variable " + varName, async () => {
|
||||||
const localVars = {};
|
const localVars: Record<string, string> = {};
|
||||||
varNames.forEach((otherVarName) => {
|
varNames.forEach((otherVarName) => {
|
||||||
if (otherVarName !== varName) {
|
if (otherVarName !== varName) {
|
||||||
localVars[otherVarName] = vars[otherVarName];
|
localVars[otherVarName] = vars[otherVarName];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await runTerraformApply(dir, localVars);
|
await runTerraformApply(dir, localVars);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
if (!(ex instanceof Error)) {
|
||||||
|
throw new Error("Unknown error generated");
|
||||||
|
}
|
||||||
|
|
||||||
expect(ex.message).toContain(
|
expect(ex.message).toContain(
|
||||||
`input variable \"${varName}\" is not set`,
|
`input variable \"${varName}\" is not set`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
|
"strict": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"types": ["bun-types"]
|
"types": ["bun-types"]
|
||||||
|
|||||||
@@ -24,9 +24,10 @@ describe("vscode-desktop", async () => {
|
|||||||
const coder_app = state.resources.find(
|
const coder_app = state.resources.find(
|
||||||
(res) => res.type == "coder_app" && res.name == "vscode",
|
(res) => res.type == "coder_app" && res.name == "vscode",
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(coder_app).not.toBeNull();
|
expect(coder_app).not.toBeNull();
|
||||||
expect(coder_app.instances.length).toBe(1);
|
expect(coder_app?.instances.length).toBe(1);
|
||||||
expect(coder_app.instances[0].attributes.order).toBeNull();
|
expect(coder_app?.instances[0].attributes.order).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds folder", async () => {
|
it("adds folder", async () => {
|
||||||
@@ -80,8 +81,9 @@ describe("vscode-desktop", async () => {
|
|||||||
const coder_app = state.resources.find(
|
const coder_app = state.resources.find(
|
||||||
(res) => res.type == "coder_app" && res.name == "vscode",
|
(res) => res.type == "coder_app" && res.name == "vscode",
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(coder_app).not.toBeNull();
|
expect(coder_app).not.toBeNull();
|
||||||
expect(coder_app.instances.length).toBe(1);
|
expect(coder_app?.instances.length).toBe(1);
|
||||||
expect(coder_app.instances[0].attributes.order).toBe(22);
|
expect(coder_app?.instances[0].attributes.order).toBe(22);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -99,11 +99,11 @@ describe("Web RDP", async () => {
|
|||||||
const defaultRdpScript = findWindowsRdpScript(defaultState);
|
const defaultRdpScript = findWindowsRdpScript(defaultState);
|
||||||
expect(defaultRdpScript).toBeString();
|
expect(defaultRdpScript).toBeString();
|
||||||
|
|
||||||
const { username: defaultUsername, password: defaultPassword } =
|
const defaultResultsGroup =
|
||||||
formEntryValuesRe.exec(defaultRdpScript)?.groups ?? {};
|
formEntryValuesRe.exec(defaultRdpScript ?? "")?.groups ?? {};
|
||||||
|
|
||||||
expect(defaultUsername).toBe("Administrator");
|
expect(defaultResultsGroup.username).toBe("Administrator");
|
||||||
expect(defaultPassword).toBe("coderRDP!");
|
expect(defaultResultsGroup.password).toBe("coderRDP!");
|
||||||
|
|
||||||
// Test that custom usernames/passwords are also forwarded correctly
|
// Test that custom usernames/passwords are also forwarded correctly
|
||||||
const customAdminUsername = "crouton";
|
const customAdminUsername = "crouton";
|
||||||
@@ -121,10 +121,10 @@ describe("Web RDP", async () => {
|
|||||||
const customRdpScript = findWindowsRdpScript(customizedState);
|
const customRdpScript = findWindowsRdpScript(customizedState);
|
||||||
expect(customRdpScript).toBeString();
|
expect(customRdpScript).toBeString();
|
||||||
|
|
||||||
const { username: customUsername, password: customPassword } =
|
const customResultsGroup =
|
||||||
formEntryValuesRe.exec(customRdpScript)?.groups ?? {};
|
formEntryValuesRe.exec(customRdpScript ?? "")?.groups ?? {};
|
||||||
|
|
||||||
expect(customUsername).toBe(customAdminUsername);
|
expect(customResultsGroup.username).toBe(customAdminUsername);
|
||||||
expect(customPassword).toBe(customAdminPassword);
|
expect(customResultsGroup.password).toBe(customAdminPassword);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user