Skip to content

Commit e5b47f7

Browse files
committed
Add a test for opening a file
1 parent cf991af commit e5b47f7

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

test/e2e/codeServer.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as path from "path"
2+
import { promises as fs } from "fs"
13
import { describe, test, expect } from "./baseFixture"
24

35
describe("CodeServer", true, [], () => {
@@ -24,4 +26,11 @@ describe("CodeServer", true, [], () => {
2426
await codeServerPage.focusTerminal()
2527
expect(await codeServerPage.page.isVisible("#terminal")).toBe(true)
2628
})
29+
30+
test("should open a file", async ({ codeServerPage }) => {
31+
const dir = await codeServerPage.dir()
32+
const file = path.join(dir, "foo")
33+
await fs.writeFile(file, "bar")
34+
await codeServerPage.openFile(file)
35+
})
2736
})

test/e2e/models/CodeServer.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class CodeServer {
3737
private process: Promise<CodeServerProcess> | undefined
3838
public readonly logger: Logger
3939
private closed = false
40+
private workspaceDir: Promise<string> | undefined
4041

4142
constructor(name: string, private readonly codeServerArgs: string[]) {
4243
this.logger = logger.named(name)
@@ -54,11 +55,18 @@ export class CodeServer {
5455
return address
5556
}
5657

58+
async dir(): Promise<string> {
59+
if (!this.workspaceDir) {
60+
this.workspaceDir = tmpdir(workspaceDir)
61+
}
62+
return this.workspaceDir
63+
}
64+
5765
/**
5866
* Create a random workspace and seed it with settings.
5967
*/
6068
private async createWorkspace(): Promise<string> {
61-
const dir = await tmpdir(workspaceDir)
69+
const dir = await this.dir()
6270
await fs.mkdir(path.join(dir, "User"))
6371
await fs.writeFile(
6472
path.join(dir, "User/settings.json"),
@@ -190,6 +198,10 @@ export class CodeServerPage {
190198
return this.codeServer.address()
191199
}
192200

201+
dir() {
202+
return this.codeServer.dir()
203+
}
204+
193205
/**
194206
* Navigate to code-server.
195207
*/
@@ -280,6 +292,23 @@ export class CodeServerPage {
280292
await this.page.waitForSelector("textarea.xterm-helper-textarea")
281293
}
282294

295+
/**
296+
* Open a file by using menus.
297+
*/
298+
async openFile(file: string) {
299+
const dir = await this.dir()
300+
await this.navigateMenus(["File", "Open File"])
301+
await this.navigatePicker([path.basename(file)])
302+
await this.waitForTab(file)
303+
}
304+
305+
/**
306+
* Wait for a tab to open for the specified file.
307+
*/
308+
async waitForTab(file: string): Promise<void> {
309+
return this.page.waitForSelector(`.tab :text("${path.basename(file)}")`)
310+
}
311+
283312
/**
284313
* Navigate to the command palette via menus then execute a command by typing
285314
* it then clicking the match from the results.

0 commit comments

Comments
 (0)