Skip to content

Commit c38acff

Browse files
authored
Fix flaky code lens test (#1056)
* Fix flaky code lens test. * Extract code lens clicking as utility.
1 parent 6033ab0 commit c38acff

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

rascal-vscode-extension/src/test/vscode-suite/dsl.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ end
222222
it("code lens works", async function() {
223223
if (errorRecovery) { this.skip(); }
224224
const editor = await ide.openModule(TestWorkspace.picoFile);
225-
const lens = await driver.wait(() => editor.getCodeLens("Rename variables a to b."), Delays.verySlow, "Rename lens should be available");
226-
await lens!.click();
225+
await ide.clickCodeLens(editor, "Rename variables a to b.", Delays.verySlow, "Rename lens should be available");
227226
await ide.assertLineBecomes(editor, 9, "b := 2;", "a variable should be changed to b");
228227
});
229228

rascal-vscode-extension/src/test/vscode-suite/repl.test.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,7 @@ describe('REPL', function () {
7474
it("import module and run in terminal", async () => {
7575
const editor = await ide.openModule(TestWorkspace.libCallFile);
7676

77-
driver.wait(async () => {
78-
try {
79-
const lens = await ide.findCodeLens(editor, "Run in new Rascal terminal");
80-
await lens!.click();
81-
return true;
82-
} catch (e) {
83-
console.log("codelens clicking failed");
84-
return false;
85-
}
86-
}, Delays.slow, "Codelens for 'Run in new Rascal terminal'");
77+
await ide.clickCodeLens(editor, "Run in new Rascal terminal");
8778
const repl = new RascalREPL(bench, driver);
8879
await repl.connect();
8980
expect(repl.lastOutput).is.equal("5\nint: 0");

rascal-vscode-extension/src/test/vscode-suite/utils.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { assert, expect } from "chai";
2929
import { stat, unlink } from "fs/promises";
3030
import * as os from 'os';
3131
import { env } from "process";
32-
import { BottomBarPanel, By, CodeLens, ContentAssist, EditorView, Key, Locator, TerminalView, TextEditor, VSBrowser, WebDriver, WebElement, WebElementCondition, Workbench, until } from "vscode-extension-tester";
32+
import { BottomBarPanel, By, ContentAssist, EditorView, Key, Locator, TerminalView, TextEditor, VSBrowser, WebDriver, WebElement, WebElementCondition, Workbench, until } from "vscode-extension-tester";
3333
import path = require("path");
3434

3535
export async function sleep(ms: number) {
@@ -428,10 +428,16 @@ export class IDEOperations {
428428
}
429429
}
430430

431-
432-
findCodeLens(editor: TextEditor, name: string, timeout = Delays.slow, message = `Cannot find code lens: ${name}`): Promise<CodeLens | undefined> {
433-
return this.driver.wait(() => ignoreFails(editor.getCodeLens(name)), timeout, message);
434-
431+
async clickCodeLens(editor: TextEditor, name: string, timeout = Delays.slow, message = `Cannot click code lens: ${name}`): Promise<void> {
432+
await this.driver.wait(async () => {
433+
try {
434+
const lens = await editor.getCodeLens(name);
435+
await lens!.click();
436+
return true;
437+
} catch (_e) {
438+
return false;
439+
}
440+
}, timeout, message);
435441
}
436442

437443
statusContains(needle: string): () => Promise<boolean> {

0 commit comments

Comments
 (0)