diff --git a/test/e2e/codeServer.test.ts b/test/e2e/codeServer.test.ts index 06eaaea0..38a6fbaf 100644 --- a/test/e2e/codeServer.test.ts +++ b/test/e2e/codeServer.test.ts @@ -1,3 +1,5 @@ +import * as path from "path" +import { promises as fs } from "fs" import { describe, test, expect } from "./baseFixture" describe("CodeServer", true, [], () => { @@ -24,4 +26,11 @@ describe("CodeServer", true, [], () => { await codeServerPage.focusTerminal() expect(await codeServerPage.page.isVisible("#terminal")).toBe(true) }) + + test("should open a file", async ({ codeServerPage }) => { + const dir = await codeServerPage.dir() + const file = path.join(dir, "foo") + await fs.writeFile(file, "bar") + await codeServerPage.openFile(file) + }) }) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index 6c32a37f..25d36c85 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -37,6 +37,7 @@ export class CodeServer { private process: Promise | undefined public readonly logger: Logger private closed = false + private workspaceDir: Promise | undefined constructor(name: string, private readonly codeServerArgs: string[]) { this.logger = logger.named(name) @@ -54,11 +55,18 @@ export class CodeServer { return address } + async dir(): Promise { + if (!this.workspaceDir) { + this.workspaceDir = tmpdir(workspaceDir) + } + return this.workspaceDir + } + /** * Create a random workspace and seed it with settings. */ private async createWorkspace(): Promise { - const dir = await tmpdir(workspaceDir) + const dir = await this.dir() await fs.mkdir(path.join(dir, "User")) await fs.writeFile( path.join(dir, "User/settings.json"), @@ -190,6 +198,10 @@ export class CodeServerPage { return this.codeServer.address() } + dir() { + return this.codeServer.dir() + } + /** * Navigate to code-server. */ @@ -280,6 +292,22 @@ export class CodeServerPage { await this.page.waitForSelector("textarea.xterm-helper-textarea") } + /** + * Open a file by using menus. + */ + async openFile(file: string) { + await this.navigateMenus(["File", "Open File"]) + await this.navigatePicker([path.basename(file)]) + await this.waitForTab(file) + } + + /** + * Wait for a tab to open for the specified file. + */ + async waitForTab(file: string): Promise { + return this.page.waitForSelector(`.tab :text("${path.basename(file)}")`) + } + /** * Navigate to the command palette via menus then execute a command by typing * it then clicking the match from the results.