Skip to content

Commit b62191a

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 b62191a

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

test/e2e/models/CodeServer.ts

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

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

301313
/**
@@ -423,7 +435,7 @@ export class CodeServerPage {
423435
let context = new Context()
424436
while (!(await Promise.race([openThenWaitClose(context), navigate(context)]))) {
425437
++attempts
426-
logger.debug("closed, retrying (${attempt}/∞)")
438+
logger.debug(`closed, retrying (${attempts}/∞)`)
427439
context.cancel()
428440
context = new Context()
429441
}

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)