Skip to content

Commit 958aa84

Browse files
committed
feat: add xterm.focus check in CodeServer
1 parent 9cc8604 commit 958aa84

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

test/e2e/models/CodeServer.ts

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export class CodeServer {
6363
const isTerminalVisible = await this.page.isVisible("#terminal")
6464
if (isTerminalVisible) {
6565
await this.page.keyboard.press(`Control+Backquote`)
66+
// Wait for terminal to receive focus
67+
await this.page.waitForSelector("div.terminal.xterm.focus")
68+
// Sometimes the terminal reloads
69+
// which is why we wait for it twice
70+
await this.page.waitForSelector("div.terminal.xterm.focus")
6671
return
6772
}
6873
// Open using the manu
@@ -76,6 +81,14 @@ export class CodeServer {
7681
// Click text=Terminal
7782
await this.page.hover("text=Terminal")
7883
await this.page.click("text=Terminal")
84+
85+
// Wait for terminal to receive focus
86+
// Sometimes the terminal reloads once or twice
87+
// which is why we wati for it to have the focus class
88+
await this.page.waitForSelector("div.terminal.xterm.focus")
89+
// Sometimes the terminal reloads
90+
// which is why we wait for it twice
91+
await this.page.waitForSelector("div.terminal.xterm.focus")
7992
}
8093

8194
/**

test/e2e/terminal.test.ts

+22-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { test, expect } from "@playwright/test"
22
import * as fs from "fs"
33
import { tmpdir } from "os"
44
import * as path from "path"
5-
5+
import util from "util"
6+
import * as cp from "child_process"
67
import { STORAGE } from "../utils/constants"
78
import { CodeServer } from "./models/CodeServer"
89

@@ -13,6 +14,8 @@ test.describe("Integrated Terminal", () => {
1314
const testFileName = "test.txt"
1415
const testString = "new string test from e2e test"
1516
let codeServer: CodeServer
17+
let tmpFolderPath: string = ""
18+
let tmpFile: string = ""
1619

1720
// TODO@jsjoeio
1821
// Fix this once https://github.com/microsoft/playwright-test/issues/240
@@ -26,25 +29,33 @@ test.describe("Integrated Terminal", () => {
2629
test.beforeEach(async ({ page }) => {
2730
codeServer = new CodeServer(page)
2831
await codeServer.setup()
29-
})
30-
31-
test("should echo a string to a file", options, async ({ page }) => {
3232
// NOTE@jsjoeio
3333
// We're not using tmpdir from src/node/constants
3434
// because Playwright doesn't fully support ES modules from
3535
// the erorrs I'm seeing
36-
const tmpFolderPath = fs.mkdtempSync(path.join(tmpdir(), "code-server-test"))
37-
const tmpFile = `${tmpFolderPath}${path.sep}${testFileName}`
36+
tmpFolderPath = fs.mkdtempSync(path.join(tmpdir(), "code-server-test"))
37+
tmpFile = `${tmpFolderPath}${path.sep}${testFileName}`
38+
})
39+
40+
test.afterEach(async () => {
41+
// Ensure directory was removed
42+
fs.rmdirSync(tmpFolderPath, { recursive: true })
43+
})
44+
45+
test("should echo a string to a file", options, async ({ page }) => {
46+
const command = `mkfifo '${tmpFile}' && cat '${tmpFile}'`
47+
const exec = util.promisify(cp.exec)
48+
const output = exec(command, { encoding: "utf8" })
49+
3850
// Open terminal and type in value
3951
await codeServer.focusTerminal()
4052

41-
// give the terminal a second to load
4253
await page.waitForLoadState("load")
43-
await page.keyboard.type(`echo '${testString}' > ${tmpFile}`)
44-
// Wait for the typing to finish before hitting enter
45-
await page.waitForTimeout(500)
54+
await page.keyboard.type(`echo '${testString}' > '${tmpFile}'`)
4655
await page.keyboard.press("Enter")
47-
await page.waitForTimeout(2000)
56+
57+
const { stdout } = await output
58+
expect(stdout).toMatch(testString)
4859

4960
// .access checks if the file exists without opening it
5061
// it doesn't return anything hence why we expect it to

0 commit comments

Comments
 (0)