Skip to content

Commit 8ff1e2e

Browse files
committed
Add e2e tests for remote storage
1 parent da7bda8 commit 8ff1e2e

3 files changed

Lines changed: 98 additions & 2 deletions

File tree

‎test/e2e/extensions/test-extension/extension.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as vscode from "vscode"
22

33
export function activate(context: vscode.ExtensionContext) {
44
vscode.window.showInformationMessage("test extension loaded")
5-
// Test extension
5+
6+
// Prints the current proxy URI into a notification.
67
context.subscriptions.push(
78
vscode.commands.registerCommand("codeServerTest.proxyUri", () => {
89
if (process.env.VSCODE_PROXY_URI) {
@@ -13,7 +14,8 @@ export function activate(context: vscode.ExtensionContext) {
1314
}),
1415
)
1516

16-
// asExternalUri extension
17+
// Asks for a URI, then runs it through asExternalUri and prints the result
18+
// into a notification.
1719
context.subscriptions.push(
1820
vscode.commands.registerCommand("codeServerTest.asExternalUri", async () => {
1921
const input = await vscode.window.showInputBox({
@@ -28,4 +30,29 @@ export function activate(context: vscode.ExtensionContext) {
2830
}
2931
}),
3032
)
33+
34+
const secretKey = "code-server-test-secret"
35+
36+
// Asks for a string, then stores it as a secret.
37+
context.subscriptions.push(
38+
vscode.commands.registerCommand("codeServerTest.setSecret", async () => {
39+
const input = await vscode.window.showInputBox({
40+
prompt: "Secret to store",
41+
})
42+
43+
if (input) {
44+
await context.secrets.store(secretKey, input)
45+
vscode.window.showInformationMessage(`set secret: ${input}`)
46+
} else {
47+
vscode.window.showErrorMessage(`Failed to run test case. No input provided.`)
48+
}
49+
}),
50+
)
51+
52+
// Prints the current secret, if any.
53+
context.subscriptions.push(
54+
vscode.commands.registerCommand("codeServerTest.getSecret", async () => {
55+
vscode.window.showInformationMessage(`get secret: ${await context.secrets.get(secretKey)}`)
56+
}),
57+
)
3158
}

‎test/e2e/extensions/test-extension/package.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
"command": "codeServerTest.asExternalUri",
2323
"title": "asExternalUri test",
2424
"category": "code-server"
25+
},
26+
{
27+
"command": "codeServerTest.setSecret",
28+
"title": "Set test secret",
29+
"category": "code-server"
30+
},
31+
{
32+
"command": "codeServerTest.getSecret",
33+
"title": "Get test secret",
34+
"category": "code-server"
2535
}
2636
]
2737
},

‎test/e2e/storage.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { promises as fs } from "fs"
2+
import * as path from "path"
3+
import { describe, test, expect } from "./baseFixture"
4+
5+
const tests = [
6+
{
7+
name: "browser storage",
8+
args: [],
9+
},
10+
{
11+
name: "remote storage",
12+
args: ["--enable-remote-storage"],
13+
},
14+
]
15+
16+
for (const test of tests) {
17+
describe(test.name, test.args, {}, () => {
18+
test("should store workbench state and secrets", async ({ codeServerPage }) => {
19+
// Create and open a file.
20+
const dir = await codeServerPage.workspaceDir
21+
const file = path.join(dir, "foo")
22+
await fs.writeFile(file, "bar")
23+
await codeServerPage.openFile(file)
24+
25+
// Store a secret.
26+
const secret = "foo-bar-baz"
27+
await codeServerPage.waitForTestExtensionLoaded()
28+
await codeServerPage.executeCommandViaMenus("code-server: Set test secret")
29+
await codeServerPage.page.waitForSelector(".quick-input-widget:focus-within")
30+
await codeServerPage.page.keyboard.type(secret)
31+
await codeServerPage.page.keyboard.press("Enter")
32+
await expect(codeServerPage.page.getByText(`set secret: ${secret}`)).toBeVisible()
33+
34+
// There should be a workspace storage directory.
35+
const userDir = path.join(dir, "User/workspaceStorage")
36+
const dirs = await fs.readdir(userDir)
37+
expect(dirs.length).toBe(1)
38+
39+
const storageFile = path.join(userDir, dirs[0], "state.vscdb")
40+
if (test.args.includes("--enable-remote-storage")) {
41+
// And a sqlite database that has the opened file in it.
42+
const content = await fs.readFile(storageFile, "utf8")
43+
expect(content).toContain(file)
44+
} else {
45+
// But no sqlite database.
46+
expect(() => fs.stat(storageFile)).rejects.toThrow("ENOENT")
47+
}
48+
49+
// Should see the same file open after a reload.
50+
await codeServerPage.page.reload({ waitUntil: "load" })
51+
await codeServerPage.waitForTab(file)
52+
53+
// Should be able to retrieve the secret.
54+
await codeServerPage.waitForTestExtensionLoaded()
55+
await codeServerPage.executeCommandViaMenus("code-server: Get test secret")
56+
await expect(codeServerPage.page.getByText(`get secret: ${secret}`)).toBeVisible()
57+
})
58+
})
59+
}

0 commit comments

Comments
 (0)