Skip to content

Commit

Permalink
Make sure the terminal opens
Browse files Browse the repository at this point in the history
The selector was timing out even though it matched more than one element
but matching on the focused one appears to work.

In addition add a loop so even it can keep trying to open the terminal
if something goes wrong with the focus.
  • Loading branch information
code-asher committed Aug 2, 2022
1 parent 602f8d4 commit 99e3167
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 18 additions & 4 deletions test/e2e/models/CodeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,24 @@ export class CodeServerPage {
async focusTerminal() {
// We need to create a new terminal since multiple tests could be running at
// once and they will step over each other if they use the same terminal.
await this.executeCommandViaMenus("Terminal: Create New Terminal")
const doFocus = async (): Promise<boolean> => {
await this.executeCommandViaMenus("Terminal: Create New Terminal")
try {
await this.page.waitForLoadState("load")
await this.page.waitForSelector("textarea.xterm-helper-textarea:focus-within", { timeout: 5000 })
return true
} catch (error) {
return false
}
}

let attempts = 1
while(!(await doFocus())) {
++attempts
this.codeServer.logger.debug(`no terminal textarea, retrying (${attempts}/∞)`)
}

// Wait for terminal textarea to show up
await this.page.waitForSelector("textarea.xterm-helper-textarea")
this.codeServer.logger.debug(`opening terminal took ${attempts} ${plural(attempts, "attempt")}`)
}

/**
Expand Down Expand Up @@ -423,7 +437,7 @@ export class CodeServerPage {
let context = new Context()
while (!(await Promise.race([openThenWaitClose(context), navigate(context)]))) {
++attempts
logger.debug("closed, retrying (${attempt}/∞)")
logger.debug(`closed, retrying (${attempts}/∞)`)
context.cancel()
context = new Context()
}
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe("Integrated Terminal", true, [], {}, () => {
// Open terminal and type in value
await codeServerPage.focusTerminal()

await codeServerPage.page.waitForLoadState("load")
await codeServerPage.page.keyboard.type(`printenv VSCODE_PROXY_URI > ${tmpFile}`)
await codeServerPage.page.keyboard.press("Enter")

Expand All @@ -34,13 +33,13 @@ describe("Integrated Terminal", true, [], {}, () => {
const tmpFolderPath = await tmpdir(testName)
const tmpFile = path.join(tmpFolderPath, "test-file")
await fs.writeFile(tmpFile, "test")
const fileName = path.basename(tmpFile)

await codeServerPage.focusTerminal()

await codeServerPage.page.waitForLoadState("load")
await codeServerPage.page.keyboard.type(`code-server ${tmpFile}`)
await codeServerPage.page.keyboard.press("Enter")

await codeServerPage.waitForTab(path.basename(tmpFile))
await codeServerPage.waitForTab(fileName)
})
})

0 comments on commit 99e3167

Please sign in to comment.