Skip to content

Commit 38497a2

Browse files
committed
chore: refactor UI tests
1 parent 58477ab commit 38497a2

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"enabled": false
1414
},
1515
"files": {
16-
"includes": ["src/**", "*.ts", "*.js", "*.json", "*.cjs", "*.mjs"]
16+
"includes": ["src/**", "test/**", "*.ts", "*.js", "*.json", "*.cjs", "*.mjs"]
1717
}
1818
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const DAY_LOG_FILE = path.join(WORKSPACE_VSCODE_DIR, ".weauditdaylog");
3434
const DEFAULT_FINDING_RANGE: LineRange = { start: 5, end: 7 };
3535
const SECONDARY_RANGE: LineRange = { start: 11, end: 13 };
3636

37+
/** Shared editor instance, set once in the `before` hook. */
38+
let editor!: TextEditor;
39+
3740
/**
3841
* Deletes a file if it exists to keep the workspace clean between tests.
3942
*/
@@ -60,7 +63,12 @@ async function readSerializedData(): Promise<SerializedData | undefined> {
6063
return undefined;
6164
}
6265
const raw = await fs.promises.readFile(WEAUDIT_FILE, "utf-8");
63-
return JSON.parse(raw) as SerializedData;
66+
try {
67+
return JSON.parse(raw) as SerializedData;
68+
} catch {
69+
// File may be mid-write; treat as not yet available.
70+
return undefined;
71+
}
6472
}
6573

6674
/**
@@ -92,35 +100,29 @@ async function openSampleFile(): Promise<TextEditor> {
92100
* Selects a snippet of text in the sample file.
93101
* Prefer this over line-range selection when the test needs stable single-line selections.
94102
*/
95-
async function selectTextInSampleFile(text: string, occurrence: number = 1): Promise<TextEditor> {
96-
const editor = await openSampleFile();
103+
async function selectTextInSampleFile(text: string, occurrence: number = 1): Promise<void> {
97104
await editor.selectText(text, occurrence);
98-
return editor;
99105
}
100106

101107
/**
102108
* Selects a range of lines by moving the caret with Shift+Arrow.
103109
*/
104-
async function selectLines(startLine: number, endLine: number): Promise<TextEditor> {
105-
const editor = await openSampleFile();
110+
async function selectLines(startLine: number, endLine: number): Promise<void> {
106111
await editor.setCursor(startLine, 1);
107112

108113
const clampedEndLine = Math.max(endLine, startLine);
109114
const downMoves = clampedEndLine - startLine + 1;
110115
for (let i = 0; i < downMoves; i++) {
111116
await editor.typeText(Key.chord(Key.SHIFT, Key.ARROW_DOWN));
112117
}
113-
return editor;
114118
}
115119

116120
/**
117121
* Moves the caret to a single location, clearing any selection.
118122
*/
119-
async function moveCursorTo(line: number, column: number = 1): Promise<TextEditor> {
120-
const editor = await openSampleFile();
123+
async function moveCursorTo(line: number, column: number = 1): Promise<void> {
121124
await editor.setCursor(line, column);
122125
await VSBrowser.instance.driver.actions({ bridge: true }).sendKeys(Key.ESCAPE).perform();
123-
return editor;
124126
}
125127

126128
/**
@@ -202,13 +204,12 @@ describe("weAudit Command UI Tests", () => {
202204
// In CI the explorer may not be ready immediately after waitForWorkbench.
203205
await VSBrowser.instance.driver.sleep(2000);
204206

205-
// Ensure the sample file can be opened before any test begins
206-
await openSampleFile();
207+
// Open the sample file once and keep a reference for the entire suite
208+
editor = await openSampleFile();
207209
});
208210

209211
beforeEach(async function () {
210212
await resetWorkspaceState(workbench);
211-
await openSampleFile();
212213
});
213214

214215
after(async function () {
@@ -388,7 +389,6 @@ describe("weAudit Command UI Tests", () => {
388389

389390
await workbench.executeCommand("weAudit: Navigate to Next Partially Audited Region");
390391

391-
const editor = await openSampleFile();
392392
const coords = await editor.getCoordinates();
393393
const cursorLine = coords[0];
394394

0 commit comments

Comments
 (0)