Skip to content

Commit bc92934

Browse files
committed
fix: reset clears testsuite and namespace nodes from tree (#390)
handleReset() only removed TestType.class items, leaving orphaned testsuite and namespace nodes in the VS Code test tree. On reload, these stale nodes caused duplicate test entries. Now deletes all non-workspace root items so the tree is fully cleared before rediscovery.
1 parent fd6f1aa commit bc92934

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

packages/extension/src/TestCollection/TestCollection.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,28 @@ class NoDatasetTest extends TestCase
17631763
}
17641764
});
17651765

1766+
it('reset should clear testsuite and namespace nodes from tree (#390)', async () => {
1767+
const collection = givenTestCollection(`
1768+
<testsuites>
1769+
<testsuite name="Unit">
1770+
<directory>tests/Unit</directory>
1771+
</testsuite>
1772+
<testsuite name="Feature">
1773+
<directory>tests/Feature</directory>
1774+
</testsuite>
1775+
</testsuites>`);
1776+
1777+
await collection.add(URI.file(phpUnitProject('tests/Unit/ExampleTest.php')));
1778+
await collection.add(URI.file(phpUnitProject('tests/Feature/ExampleTest.php')));
1779+
1780+
expect(ctrl.items.size).toBeGreaterThan(0);
1781+
1782+
collection.reset();
1783+
1784+
// After reset, the VS Code tree should be completely empty
1785+
expect(ctrl.items.size).toBe(0);
1786+
});
1787+
17661788
it('add test — all fixture files discovered', async () => {
17671789
const collection = givenTestCollection(`
17681790
<testsuites>

packages/extension/src/TestCollection/TestCollection.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,11 @@ export class TestCollection extends BaseTestCollection {
195195
private handleReset() {
196196
const workspaceDefs = this.index.getDefinitionsByType(TestType.workspace);
197197

198-
for (const [testItem] of this.index.getDefinitionsByType(TestType.class)) {
199-
if (!testItem.parent) {
200-
this.rootItems.delete(testItem.id);
201-
continue;
198+
const keepIds = new Set(workspaceDefs.map(([item]) => item.id));
199+
for (const [id] of this.rootItems) {
200+
if (!keepIds.has(id)) {
201+
this.rootItems.delete(id);
202202
}
203-
204-
testItem.parent.children.delete(testItem.id);
205203
}
206204
this.index.clear();
207205

0 commit comments

Comments
 (0)