Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

- Don't start debugging XCTest cases if the swift-testing debug session was stopped ([#1797](https://github.com/swiftlang/vscode-swift/pull/1797))
- Improve error handling when the swift path is misconfigured ([#1801](https://github.com/swiftlang/vscode-swift/pull/1801))
- Fix an error when performing "Run/Debug Tests Multiple Times" on Linux ([#1824](https://github.com/swiftlang/vscode-swift/pull/1824))

## 2.11.20250806 - 2025-08-06

Expand Down
24 changes: 19 additions & 5 deletions src/commands/testMultipleTimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ export async function runTestMultipleTimes(
}
const token = new vscode.CancellationTokenSource();
const testExplorer = currentFolder.testExplorer;
const request = new vscode.TestRunRequest(tests);
const runner = new TestRunner(
kind,
new vscode.TestRunRequest(tests),
request,
currentFolder,
testExplorer.controller,
token.token
Expand Down Expand Up @@ -110,9 +111,7 @@ export async function runTestMultipleTimes(
* also accept a final count parameter. We have to find the count parameter ourselves since JavaScript
* only supports varargs at the end of an argument list.
*/
export function extractTestItemsAndCount(
...args: (vscode.TestItem | number | undefined | null)[]
): {
export function extractTestItemsAndCount(...args: unknown[]): {
testItems: vscode.TestItem[];
count?: number;
} {
Expand All @@ -126,9 +125,12 @@ export function extractTestItemsAndCount(
} else if (typeof arg === "number" && index === args.length - 1) {
result.count = arg ?? undefined;
return result;
} else if (typeof arg === "object") {
} else if (isVSCodeTestItem(arg)) {
result.testItems.push(arg);
return result;
} else if (typeof arg === "object") {
// Object but not a TestItem, just skip it
return result;
} else {
throw new Error(`Unexpected argument ${arg} at index ${index}`);
}
Expand All @@ -137,3 +139,15 @@ export function extractTestItemsAndCount(
);
return result;
}

/**
* Checks if an object is a vscode.TestItem via duck typing.
*/
function isVSCodeTestItem(obj: unknown): obj is vscode.TestItem {
return (
typeof obj === "object" &&
obj !== null &&
Object.prototype.hasOwnProperty.call(obj, "id") &&
Object.prototype.hasOwnProperty.call(obj, "uri")
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ suite("Test Explorer Suite", function () {
await vscode.commands.executeCommand(
Commands.RUN_TESTS_MULTIPLE_TIMES,
testItems[0],
{ preserveFocus: true }, // a trailing argument included on Linux
numIterations
);

Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/commands/runTestMultipleTimes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { extractTestItemsAndCount } from "../../../src/commands/testMultipleTime
suite("Run Tests Multiple Times", () => {
suite("extractTestItemsAndCount()", () => {
function createDummyTestItem(label: string): vscode.TestItem {
return { label } as vscode.TestItem;
return { id: label, uri: vscode.Uri.file(`/dummy/path/${label}`) } as vscode.TestItem;
}

test("handles empty arguments", () => {
Expand Down