mirror of
https://git.tuxpa.in/a/code-server.git
synced 2025-01-20 06:18:45 +00:00
Add a test for opening a file
This commit is contained in:
parent
cf991afb33
commit
8ce6730810
@ -1,3 +1,5 @@
|
|||||||
|
import * as path from "path"
|
||||||
|
import { promises as fs } from "fs"
|
||||||
import { describe, test, expect } from "./baseFixture"
|
import { describe, test, expect } from "./baseFixture"
|
||||||
|
|
||||||
describe("CodeServer", true, [], () => {
|
describe("CodeServer", true, [], () => {
|
||||||
@ -24,4 +26,11 @@ describe("CodeServer", true, [], () => {
|
|||||||
await codeServerPage.focusTerminal()
|
await codeServerPage.focusTerminal()
|
||||||
expect(await codeServerPage.page.isVisible("#terminal")).toBe(true)
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -37,6 +37,7 @@ export class CodeServer {
|
|||||||
private process: Promise<CodeServerProcess> | undefined
|
private process: Promise<CodeServerProcess> | undefined
|
||||||
public readonly logger: Logger
|
public readonly logger: Logger
|
||||||
private closed = false
|
private closed = false
|
||||||
|
private workspaceDir: Promise<string> | undefined
|
||||||
|
|
||||||
constructor(name: string, private readonly codeServerArgs: string[]) {
|
constructor(name: string, private readonly codeServerArgs: string[]) {
|
||||||
this.logger = logger.named(name)
|
this.logger = logger.named(name)
|
||||||
@ -54,11 +55,18 @@ export class CodeServer {
|
|||||||
return address
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async dir(): Promise<string> {
|
||||||
|
if (!this.workspaceDir) {
|
||||||
|
this.workspaceDir = tmpdir(workspaceDir)
|
||||||
|
}
|
||||||
|
return this.workspaceDir
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a random workspace and seed it with settings.
|
* Create a random workspace and seed it with settings.
|
||||||
*/
|
*/
|
||||||
private async createWorkspace(): Promise<string> {
|
private async createWorkspace(): Promise<string> {
|
||||||
const dir = await tmpdir(workspaceDir)
|
const dir = await this.dir()
|
||||||
await fs.mkdir(path.join(dir, "User"))
|
await fs.mkdir(path.join(dir, "User"))
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
path.join(dir, "User/settings.json"),
|
path.join(dir, "User/settings.json"),
|
||||||
@ -190,6 +198,10 @@ export class CodeServerPage {
|
|||||||
return this.codeServer.address()
|
return this.codeServer.address()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dir() {
|
||||||
|
return this.codeServer.dir()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to code-server.
|
* Navigate to code-server.
|
||||||
*/
|
*/
|
||||||
@ -280,6 +292,22 @@ export class CodeServerPage {
|
|||||||
await this.page.waitForSelector("textarea.xterm-helper-textarea")
|
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<void> {
|
||||||
|
return this.page.waitForSelector(`.tab :text("${path.basename(file)}")`)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to the command palette via menus then execute a command by typing
|
* Navigate to the command palette via menus then execute a command by typing
|
||||||
* it then clicking the match from the results.
|
* it then clicking the match from the results.
|
||||||
|
Loading…
Reference in New Issue
Block a user