Skip to content

Commit e6139cd

Browse files
committed
fix: flaky
1 parent 226056f commit e6139cd

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

test/extension/suite/treeViews.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ suite("Tree View Integration", () => {
4747

4848
// Toggle the mode
4949
await vscode.commands.executeCommand("weAudit.toggleTreeViewMode");
50-
await new Promise((resolve) => setTimeout(resolve, 300));
5150

52-
// Get a fresh configuration object to see the updated value
53-
const modeAfter = vscode.workspace.getConfiguration("weAudit").get<string>("general.treeViewMode");
51+
// Poll until the configuration value changes (the update is async)
52+
let modeAfter: string | undefined;
53+
const deadline = Date.now() + 5_000;
54+
while (Date.now() < deadline) {
55+
modeAfter = vscode.workspace.getConfiguration("weAudit").get<string>("general.treeViewMode");
56+
if (modeAfter !== modeBefore) {
57+
break;
58+
}
59+
await new Promise((resolve) => setTimeout(resolve, 100));
60+
}
61+
5462
assert.notStrictEqual(modeAfter, modeBefore, "Tree view mode should change after toggle");
5563

5664
// Verify it's one of the valid values

test/ui/suite/commands.ui.test.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,61 @@ async function readSerializedData(): Promise<SerializedData | undefined> {
7575
* Opens the sample file, using the file picker when needed.
7676
*/
7777
async function openSampleFile(): Promise<TextEditor> {
78-
// Try the fast path first: the tab is already open.
78+
// Fast path: the tab is already open.
7979
try {
8080
return (await new EditorView().openEditor(SAMPLE_FILE_BASENAME)) as TextEditor;
8181
} catch {
82-
// Tab not open yet — ask VS Code to open the file and poll until the
83-
// tab appears. On CI (xvfb) the workspace may still be initialising,
84-
// so we re-issue openResources on every retry to be safe.
85-
await waitForCondition(
82+
// Tab not open yet. Try the code CLI first; if that doesn't work
83+
// (common on Linux CI where the CLI can't reach the chromedriver-
84+
// managed VS Code instance), fall back to Quick Open via the
85+
// command palette.
86+
try {
87+
await VSBrowser.instance.openResources(SAMPLE_FILE);
88+
} catch {
89+
/* ignore – we'll fall through to Quick Open */
90+
}
91+
92+
let found = await waitForCondition(
8693
async () => {
8794
try {
88-
await VSBrowser.instance.openResources(SAMPLE_FILE);
8995
await new EditorView().openEditor(SAMPLE_FILE_BASENAME);
9096
return true;
9197
} catch {
9298
return false;
9399
}
94100
},
95-
30_000,
96-
1_000,
101+
10_000,
102+
500,
97103
);
104+
105+
if (!found) {
106+
// Quick Open fallback: open the command palette, clear the ">"
107+
// prefix so it becomes a file search, type the filename, and
108+
// confirm.
109+
await waitForCondition(
110+
async () => {
111+
try {
112+
const prompt = await new Workbench().openCommandPrompt();
113+
await prompt.setText(SAMPLE_FILE_BASENAME);
114+
await VSBrowser.instance.driver.sleep(1_000);
115+
await prompt.confirm();
116+
await VSBrowser.instance.driver.sleep(500);
117+
await new EditorView().openEditor(SAMPLE_FILE_BASENAME);
118+
return true;
119+
} catch {
120+
try {
121+
await VSBrowser.instance.driver.actions({ bridge: true }).sendKeys(Key.ESCAPE).perform();
122+
} catch {
123+
/* ignore */
124+
}
125+
return false;
126+
}
127+
},
128+
20_000,
129+
2_000,
130+
);
131+
}
132+
98133
return (await new EditorView().openEditor(SAMPLE_FILE_BASENAME)) as TextEditor;
99134
}
100135
}

0 commit comments

Comments
 (0)