Skip to content

Commit 99e3167

Browse files
committed
Make sure the terminal opens
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.
1 parent 602f8d4 commit 99e3167

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

test/e2e/models/CodeServer.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,24 @@ export class CodeServerPage {
292292
async focusTerminal() {
293293
// We need to create a new terminal since multiple tests could be running at
294294
// once and they will step over each other if they use the same terminal.
295-
await this.executeCommandViaMenus("Terminal: Create New Terminal")
295+
const doFocus = async (): Promise<boolean> => {
296+
await this.executeCommandViaMenus("Terminal: Create New Terminal")
297+
try {
298+
await this.page.waitForLoadState("load")
299+
await this.page.waitForSelector("textarea.xterm-helper-textarea:focus-within", { timeout: 5000 })
300+
return true
301+
} catch (error) {
302+
return false
303+
}
304+
}
305+
306+
let attempts = 1
307+
while(!(await doFocus())) {
308+
++attempts
309+
this.codeServer.logger.debug(`no terminal textarea, retrying (${attempts}/∞)`)
310+
}
296311

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

301315
/**
@@ -423,7 +437,7 @@ export class CodeServerPage {
423437
let context = new Context()
424438
while (!(await Promise.race([openThenWaitClose(context), navigate(context)]))) {
425439
++attempts
426-
logger.debug("closed, retrying (${attempt}/∞)")
440+
logger.debug(`closed, retrying (${attempts}/∞)`)
427441
context.cancel()
428442
context = new Context()
429443
}

test/e2e/terminal.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe("Integrated Terminal", true, [], {}, () => {
2222
// Open terminal and type in value
2323
await codeServerPage.focusTerminal()
2424

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

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

3838
await codeServerPage.focusTerminal()
3939

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

44-
await codeServerPage.waitForTab(path.basename(tmpFile))
43+
await codeServerPage.waitForTab(fileName)
4544
})
4645
})

0 commit comments

Comments
 (0)