Skip to content

Commit 7529975

Browse files
committed
refactor: CodeServer methods to be mroe stable
1 parent dd21c10 commit 7529975

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

test/e2e/models/CodeServer.ts

+27-31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CODE_SERVER_ADDRESS } from "../../utils/constants"
55
// See Playwright docs: https://playwright.dev/docs/pom/
66
export class CodeServer {
77
page: Page
8+
editorSelector = "div.monaco-workbench"
89

910
constructor(page: Page) {
1011
this.page = page
@@ -30,15 +31,18 @@ export class CodeServer {
3031
// but usually a reload or two fixes it
3132
// TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
3233
while (!editorIsVisible) {
34+
// When a reload happens, we want to wait for all resources to be
35+
// loaded completely. Hence why we use that instead of DOMContentLoaded
36+
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
37+
await this.page.waitForLoadState("load")
38+
// Give it an extra second just in case it's feeling extra slow
39+
await this.page.waitForTimeout(1000)
3340
reloadCount += 1
3441
if (await this.isEditorVisible()) {
3542
console.log(` Editor became visible after ${reloadCount} reloads`)
3643
break
3744
}
38-
// When a reload happens, we want to wait for all resources to be
39-
// loaded completely. Hence why we use that instead of DOMContentLoaded
40-
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
41-
await this.page.reload({ waitUntil: "load" })
45+
await this.page.reload()
4246
}
4347
}
4448

@@ -49,47 +53,39 @@ export class CodeServer {
4953
// Make sure the editor actually loaded
5054
// If it's not visible after 5 seconds, something is wrong
5155
await this.page.waitForLoadState("networkidle")
52-
return await this.page.isVisible("div.monaco-workbench", { timeout: 5000 })
56+
return await this.page.isVisible(this.editorSelector)
5357
}
5458

5559
/**
5660
* Focuses Integrated Terminal
57-
* by going to the Application Menu
58-
* and clicking View > Terminal
61+
* by using "Terminal: Focus Terminal"
62+
* from the Command Palette
63+
*
64+
* This should focus the terminal no matter
65+
* if it already has focus and/or is or isn't
66+
* visible already.
5967
*/
6068
async focusTerminal() {
61-
// If the terminal is already visible
62-
// then we can focus it by hitting the keyboard shortcut
63-
const isTerminalVisible = await this.page.isVisible("#terminal")
64-
if (isTerminalVisible) {
65-
await this.page.keyboard.press(`Control+Backquote`)
66-
// TODO fix this
67-
// Wait for terminal to receive focus
68-
await this.page.waitForSelector("div.terminal.xterm.focus")
69-
// Sometimes the terminal reloads
70-
// which is why we wait for it twice
71-
await this.page.waitForSelector("div.terminal.xterm.focus")
72-
return
73-
}
74-
// Open using the manu
7569
// Click [aria-label="Application Menu"] div[role="none"]
7670
await this.page.click('[aria-label="Application Menu"] div[role="none"]')
7771

7872
// Click text=View
7973
await this.page.hover("text=View")
8074
await this.page.click("text=View")
8175

82-
// Click text=Terminal
83-
await this.page.hover("text=Terminal")
84-
await this.page.click("text=Terminal")
76+
// Click text=Command Palette
77+
await this.page.hover("text=Command Palette")
78+
await this.page.click("text=Command Palette")
79+
80+
// Type Terminal: Focus Terminal
81+
await this.page.keyboard.type("Terminal: Focus Terminal")
82+
83+
// Click Terminal: Focus Terminal
84+
await this.page.hover("text=Terminal: Focus Terminal")
85+
await this.page.click("text=Terminal: Focus Terminal")
8586

86-
// Wait for terminal to receive focus
87-
// Sometimes the terminal reloads once or twice
88-
// which is why we wait for it to have the focus class
89-
await this.page.waitForSelector("div.terminal.xterm.focus")
90-
// Sometimes the terminal reloads
91-
// which is why we wait for it twice
92-
await this.page.waitForSelector("div.terminal.xterm.focus")
87+
// Wait for terminal textarea to show up
88+
await this.page.waitForSelector("textarea.xterm-helper-textarea")
9389
}
9490

9591
/**

test/e2e/terminal.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ test.describe("Integrated Terminal", () => {
5252
await page.waitForLoadState("load")
5353
await page.keyboard.type(`echo '${testString}' > '${tmpFile}'`)
5454
await page.keyboard.press("Enter")
55+
// It may take a second to process
56+
await page.waitForTimeout(1000)
5557

5658
const { stdout } = await output
5759
expect(stdout).toMatch(testString)

0 commit comments

Comments
 (0)