|
| 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