Skip to content

Commit 47227f8

Browse files
committed
fix(terminal): replace awaits() with awaitsFor() in integration tests
Use condition-based polling instead of fixed timeouts to prevent flaky tests. Add waitForShellReady() and waitForActiveProcess() helpers that trigger flyout process refresh and poll the flyout title text.
1 parent 27fe3fd commit 47227f8

1 file changed

Lines changed: 62 additions & 25 deletions

File tree

test/spec/Terminal-integ-test.js

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*/
2020

21-
/*global describe, it, expect, beforeAll, afterAll, awaitsFor, awaits */
21+
/*global describe, it, expect, beforeAll, afterAll, awaitsFor */
2222

2323
define(function (require, exports, module) {
2424

@@ -102,6 +102,47 @@ define(function (require, exports, module) {
102102
).text();
103103
}
104104

105+
/**
106+
* Trigger a flyout process refresh so tab titles
107+
* reflect the current foreground process.
108+
*/
109+
function triggerFlyoutRefresh() {
110+
testWindow.$(".terminal-tab-flyout")
111+
.trigger("mouseenter");
112+
}
113+
114+
/**
115+
* Wait for the active terminal's shell to initialize.
116+
* The flyout title text changes from "Terminal" to the
117+
* shell name (e.g. "bash") once process info is fetched.
118+
*/
119+
async function waitForShellReady() {
120+
await awaitsFor(function () {
121+
triggerFlyoutRefresh();
122+
const title = testWindow.$(
123+
".terminal-flyout-item.active "
124+
+ ".terminal-flyout-title"
125+
).text();
126+
return title && title !== "Terminal";
127+
}, "shell to initialize", 10000);
128+
}
129+
130+
/**
131+
* Wait for a child process (e.g. "node") to appear as
132+
* the active terminal's foreground process in the flyout.
133+
*/
134+
async function waitForActiveProcess(processName) {
135+
await awaitsFor(function () {
136+
triggerFlyoutRefresh();
137+
const title = testWindow.$(
138+
".terminal-flyout-item.active "
139+
+ ".terminal-flyout-title"
140+
).text();
141+
return title && title.indexOf(processName) !== -1;
142+
}, processName + " process to appear in flyout",
143+
15000);
144+
}
145+
105146
/**
106147
* Write data to the active terminal's PTY via the
107148
* terminal extension's test helper.
@@ -150,29 +191,25 @@ define(function (require, exports, module) {
150191
.is(":visible")).toBeTrue();
151192
expect(getTerminalCount()).toBe(1);
152193

153-
// Wait for shell to start, then run `pwd`/`cd`
154-
// to verify cwd. Use node for cross-platform.
155-
await awaits(2000);
194+
// The shell sets its title to include the cwd
195+
// (e.g. "user@host: /path/to/project").
196+
// Wait for the flyout tooltip to contain the
197+
// project directory name.
198+
const expectedPath = getNativeProjectPath();
199+
const projectDirName = expectedPath
200+
.split("/").pop().split("\\").pop();
156201

157-
// Use node to print cwd — works on all platforms
158-
await writeToTerminal(
159-
'node -e "process.stdout.write(process.cwd())"\r'
160-
);
161-
await awaits(1000);
202+
await awaitsFor(function () {
203+
const title = testWindow.$(
204+
".terminal-flyout-item.active"
205+
).attr("title") || "";
206+
return title.indexOf(projectDirName) !== -1;
207+
}, "terminal title to contain project dir",
208+
10000);
162209

163-
// The terminal title typically contains the cwd.
164-
// Also verify via the flyout tooltip which holds
165-
// the full terminal title.
166-
const expectedPath = getNativeProjectPath();
167210
const flyoutTitle = testWindow.$(
168211
".terminal-flyout-item.active"
169212
).attr("title") || "";
170-
171-
// The title format is "user@host: /path" — the
172-
// path portion should end with our project dir.
173-
// Extract last path component for a robust check.
174-
const projectDirName = expectedPath.split("/").pop()
175-
.split("\\").pop();
176213
expect(flyoutTitle).toContain(projectDirName);
177214
});
178215

@@ -186,7 +223,7 @@ define(function (require, exports, module) {
186223
return getTerminalCount() === 1;
187224
}, "single terminal to exist", 5000);
188225

189-
await awaits(1000);
226+
await waitForShellReady();
190227

191228
clickPanelCloseButton();
192229

@@ -214,7 +251,7 @@ define(function (require, exports, module) {
214251
return getTerminalCount() === 2;
215252
}, "second terminal", 10000);
216253

217-
await awaits(1000);
254+
await waitForShellReady();
218255

219256
clickPanelCloseButton();
220257

@@ -266,13 +303,13 @@ define(function (require, exports, module) {
266303
return getTerminalCount() === 1;
267304
}, "terminal to be created", 10000);
268305

269-
await awaits(2000);
306+
await waitForShellReady();
270307

271308
// Start a long-running node process
272309
await writeToTerminal(
273310
'node -e "setTimeout(()=>{},60000)"\r'
274311
);
275-
await awaits(2000);
312+
await waitForActiveProcess("node");
276313

277314
clickPanelCloseButton();
278315

@@ -322,12 +359,12 @@ define(function (require, exports, module) {
322359
return getTerminalCount() === 2;
323360
}, "second terminal", 10000);
324361

325-
await awaits(2000);
362+
await waitForShellReady();
326363

327364
await writeToTerminal(
328365
'node -e "setTimeout(()=>{},60000)"\r'
329366
);
330-
await awaits(2000);
367+
await waitForActiveProcess("node");
331368

332369
clickPanelCloseButton();
333370

0 commit comments

Comments
 (0)