Skip to content

Commit 6841205

Browse files
committed
test: update
1 parent f194e27 commit 6841205

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

test/ui/command.test.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ describe("Command Tests", function() {
4747
fse.copySync(projectPath, projectFolder);
4848
await VSBrowser.instance.openResources(projectFolder);
4949
currentProjectPath = projectFolder;
50-
// On Linux the workspace trust dialog appears before the folder is actually loaded.
51-
// Dismiss it here so subsequent steps see a fully opened workspace.
52-
await sleep(2000);
50+
// openResources() sends the CLI IPC command and returns immediately, before VS Code
51+
// has actually reloaded the window with the new folder. On Linux the IPC + reload
52+
// cycle is slower; calling openFile() right after can race with or even abort the
53+
// folder load. Poll the window title until it contains the folder name so we know
54+
// VS Code has finished the workspace transition before we proceed.
55+
await waitForWorkspaceOpen(path.basename(projectFolder));
5356
await dismissModalDialogIfPresent();
5457
await ensureExplorerIsOpen();
5558
}
@@ -554,3 +557,23 @@ async function ensureExplorerIsOpen() {
554557
await control.openView();
555558
}
556559

560+
/**
561+
* Poll the VS Code window title until it contains {@link folderName}, which signals that
562+
* VS Code has finished the workspace-reload triggered by openResources(). Falls back
563+
* silently after {@link timeoutMs} so tests can still run and produce useful error messages.
564+
*/
565+
async function waitForWorkspaceOpen(folderName: string, timeoutMs: number = 30000): Promise<void> {
566+
const start = Date.now();
567+
while (Date.now() - start < timeoutMs) {
568+
try {
569+
const title = await VSBrowser.instance.driver.getTitle();
570+
if (title.toLowerCase().includes(folderName.toLowerCase())) {
571+
return;
572+
}
573+
} catch (_e) {
574+
// VS Code is mid-reload; its window title is temporarily unavailable.
575+
}
576+
await sleep(1000);
577+
}
578+
}
579+

0 commit comments

Comments
 (0)