Skip to content

Commit 13b707d

Browse files
authored
Add tag to skipped test (#1415)
Add a `skipped` tag to tests in the test explorer if they were skipped in the last run. This lets users filter down just the skipped tests in a test run.
1 parent ff3ca28 commit 13b707d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/TestExplorer/TestRunner.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export class TestRunProxy {
122122
if (this.runStarted) {
123123
return;
124124
}
125+
126+
this.resetTags(this.controller);
125127
this.runStarted = true;
126128

127129
// When a test run starts we need to do several things:
@@ -191,6 +193,14 @@ export class TestRunProxy {
191193
const attachments = this.attachments[testIndex] ?? [];
192194
attachments.push(attachment);
193195
this.attachments[testIndex] = attachments;
196+
197+
const testItem = this.testItems[testIndex];
198+
if (testItem) {
199+
testItem.tags = [
200+
...testItem.tags,
201+
new vscode.TestTag(TestRunProxy.Tags.HAS_ATTACHMENT),
202+
];
203+
}
194204
};
195205

196206
public getTestIndex(id: string, filename?: string): number {
@@ -214,6 +224,8 @@ export class TestRunProxy {
214224
}
215225

216226
public skipped(test: vscode.TestItem) {
227+
test.tags = [...test.tags, new vscode.TestTag(TestRunProxy.Tags.SKIPPED)];
228+
217229
this.runState.skipped.push(test);
218230
this.testRun?.skipped(test);
219231
}
@@ -323,6 +335,20 @@ export class TestRunProxy {
323335
// Compute final coverage numbers if any coverage info has been captured during the run.
324336
await this.coverage.computeCoverage(this.testRun);
325337
}
338+
339+
private static Tags = {
340+
SKIPPED: "skipped",
341+
HAS_ATTACHMENT: "hasAttachment",
342+
};
343+
344+
// Remove any tags that were added due to test results
345+
private resetTags(controller: vscode.TestController) {
346+
function removeTestRunTags(_acc: void, test: vscode.TestItem) {
347+
const tags = Object.values(TestRunProxy.Tags);
348+
test.tags = test.tags.filter(tag => !tags.includes(tag.id));
349+
}
350+
reduceTestItemChildren(controller.items, removeTestRunTags, void 0);
351+
}
326352
}
327353

328354
/** Class used to run tests */

test/integration-tests/testexplorer/TestExplorerIntegration.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ suite("Test Explorer Suite", function () {
303303
assertTestResults(testRun, {
304304
skipped: ["PackageTests.testWithKnownIssue()"],
305305
});
306+
307+
const testItem = testRun.testItems.find(
308+
({ id }) => id === "PackageTests.testWithKnownIssue()"
309+
);
310+
assert.ok(testItem, "Unable to find test item for testWithKnownIssue");
311+
assert.ok(
312+
testItem.tags.find(tag => tag.id === "skipped"),
313+
"skipped tag was not found on test item"
314+
);
306315
});
307316

308317
test("testWithKnownIssueAndUnknownIssue", async () => {

0 commit comments

Comments
 (0)