Skip to content

Commit 18dcd17

Browse files
committed
refactor: improve test resilience and code readability
- Use expect.objectContaining in tests for better resilience to future option additions - Extract showTextDocument options to named constant for improved readability - Addresses Copilot review feedback on PR #5282
1 parent 99e7feb commit 18dcd17

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,9 @@ export class DiffViewProvider {
503503

504504
// Pre-open the file as a text document to ensure it doesn't open in preview mode
505505
// This fixes issues with files that have custom editor associations (like markdown preview)
506+
const showOptions = { preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true }
506507
vscode.window
507-
.showTextDocument(uri, { preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true })
508+
.showTextDocument(uri, showOptions)
508509
.then(() => {
509510
// Execute the diff command after ensuring the file is open as text
510511
return vscode.commands.executeCommand(

src/integrations/editor/__tests__/DiffViewProvider.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ describe("DiffViewProvider", () => {
176176
// Mock showTextDocument to track when it's called
177177
vi.mocked(vscode.window.showTextDocument).mockImplementation(async (uri, options) => {
178178
callOrder.push("showTextDocument")
179-
expect(options).toEqual({ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true })
179+
expect(options).toEqual(
180+
expect.objectContaining({
181+
preview: false,
182+
viewColumn: vscode.ViewColumn.Active,
183+
preserveFocus: true,
184+
}),
185+
)
180186
return mockEditor as any
181187
})
182188

@@ -211,7 +217,7 @@ describe("DiffViewProvider", () => {
211217
// Verify that showTextDocument was called with preview: false
212218
expect(vscode.window.showTextDocument).toHaveBeenCalledWith(
213219
expect.objectContaining({ fsPath: `${mockCwd}/test.md` }),
214-
{ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true },
220+
expect.objectContaining({ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true }),
215221
)
216222

217223
// Verify that the diff command was executed

0 commit comments

Comments
 (0)