diff --git a/src/vs/workbench/api/common/extHostTesting.ts b/src/vs/workbench/api/common/extHostTesting.ts index ac0487a7540..da3c546066d 100644 --- a/src/vs/workbench/api/common/extHostTesting.ts +++ b/src/vs/workbench/api/common/extHostTesting.ts @@ -267,11 +267,8 @@ export class ExtHostTesting implements ExtHostTestingShape { } } - const internal = this.getInternalTestForReference(test); - if (internal) { - this.flushCollectionDiffs(); - this.proxy.$updateTestStateInRun(req.runId, internal.item.extId, TestState.from(state)); - } + this.flushCollectionDiffs(); + this.proxy.$updateTestStateInRun(req.runId, test.id, TestState.from(state)); }, tests: includeTests.map(t => TestItemFilteredWrapper.unwrap(t.actual)), exclude: excludeTests.map(([, t]) => TestItemFilteredWrapper.unwrap(t.actual)), @@ -331,6 +328,14 @@ export class ExtHostTesting implements ExtHostTestingShape { return; } + const onDidInvalidateTest = new Emitter(); + workspaceHierarchy.onDidInvalidateTest?.(node => { + const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(node, document); + if (wrapper.hasNodeMatchingFilter) { + onDidInvalidateTest.fire(wrapper); + } + }); + const onDidChangeTest = new Emitter(); workspaceHierarchy.onDidChangeTest(node => { const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(node, document); @@ -373,6 +378,8 @@ export class ExtHostTesting implements ExtHostTestingShape { onDidChangeTest.dispose(); TestItemFilteredWrapper.removeFilter(document); }, + discoveredInitialTests: workspaceHierarchy.discoveredInitialTests, + onDidInvalidateTest: onDidInvalidateTest.event, onDidChangeTest: onDidChangeTest.event }; } diff --git a/src/vs/workbench/contrib/testing/common/ownedTestCollection.ts b/src/vs/workbench/contrib/testing/common/ownedTestCollection.ts index e9895e00094..64065246000 100644 --- a/src/vs/workbench/contrib/testing/common/ownedTestCollection.ts +++ b/src/vs/workbench/contrib/testing/common/ownedTestCollection.ts @@ -271,6 +271,13 @@ export class SingleUseTestCollection implements IDisposable { const deletedChildren = internal.previousChildren; const currentChildren = new Set(); for (const child of actual.children) { + // If a child was recreated, delete the old object before calling + // addItem() anew. + const previous = this.testIdToInternal.object.get(child.id); + if (previous && previous.actual !== child) { + this.removeItembyId(child.id); + } + const c = this.addItem(child, providerId, internal.item.extId); deletedChildren.delete(c.item.extId); currentChildren.add(c.item.extId);