Skip to content

Commit 1317bbd

Browse files
committed
added tests for vscode-web
1 parent 1823248 commit 1317bbd

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

dotfiles/main.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ describe("dotfiles", async () => {
1212
agent_id: "foo",
1313
});
1414

15+
it("default output", async () => {
16+
const state = await runTerraformApply(import.meta.dir, {
17+
agent_id: "foo",
18+
});
19+
expect(state.outputs.dotfiles_uri.value).toBe("");
20+
});
1521
});

test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const findResourceInstance = <T extends "coder_script" | string>(
129129
return resource.instances[0].attributes as any;
130130
};
131131

132-
// assertRequiredVariables creates a test-case
132+
// testRequiredVariables creates a test-case
133133
// for each variable provided and ensures that
134134
// the apply fails without it.
135135
export const testRequiredVariables = (

vscode-web/main.test.ts

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
executeScriptInContainer,
4+
runTerraformApply,
5+
runTerraformInit,
6+
} from "../test";
7+
8+
describe("vscode-web", async () => {
9+
await runTerraformInit(import.meta.dir);
10+
11+
12+
// replaces testRequiredVariables due to license var
13+
it("missing agent_id", async () => {
14+
try {
15+
await runTerraformApply(import.meta.dir, {
16+
accept_license: "true",
17+
});
18+
} catch (ex) {
19+
expect(ex.message).toContain(
20+
'input variable "agent_id" is not set'
21+
);
22+
}
23+
});
24+
25+
it("invalid license_agreement", async () => {
26+
27+
try {
28+
await runTerraformApply(import.meta.dir, {
29+
agent_id: "foo",
30+
});
31+
} catch (ex) {
32+
expect(ex.message).toContain(
33+
'You must accept the VS Code license agreement by setting accept_license=true'
34+
);
35+
}
36+
});
37+
38+
it("fails without curl", async () => {
39+
const state = await runTerraformApply(import.meta.dir, {
40+
agent_id: "foo",
41+
accept_license: "true",
42+
});
43+
const output = await executeScriptInContainer(state, "alpine");
44+
expect(output.exitCode).toBe(1);
45+
expect(output.stdout).toEqual([
46+
"\u001b[0;1mInstalling vscode-cli!",
47+
"Failed to install vscode-cli:", // TODO: manually test error log
48+
]);
49+
});
50+
51+
it("runs with curl", async () => {
52+
const state = await runTerraformApply(import.meta.dir, {
53+
agent_id: "foo",
54+
accept_license: "true",
55+
});
56+
const output = await executeScriptInContainer(state, "alpine/curl");
57+
expect(output.exitCode).toBe(0);
58+
expect(output.stdout).toEqual([
59+
"\u001b[0;1mInstalling vscode-cli!",
60+
"🥳 vscode-cli has been installed.",
61+
"",
62+
"👷 Running /tmp/vscode-cli/bin/code serve-web --port 13338 --without-connection-token --accept-server-license-terms in the background...",
63+
"Check logs at /tmp/vscode-web.log!"
64+
]);
65+
});
66+
67+
});

0 commit comments

Comments
 (0)