testing: better approach to deserializing test items

This commit is contained in:
Connor Peet
2022-03-31 10:25:09 -07:00
parent 93d5dd8b68
commit 804dc2f7de
3 changed files with 27 additions and 24 deletions

View File

@@ -4,11 +4,12 @@
*--------------------------------------------------------------------------------------------*/
import * as editorRange from 'vs/editor/common/core/range';
import { createPrivateApiFor, getPrivateApiFor, IExtHostTestItemApi } from 'vs/workbench/api/common/extHostTestingPrivateApi';
import { TestIdPathParts } from 'vs/workbench/contrib/testing/common/testId';
import { TestId, TestIdPathParts } from 'vs/workbench/contrib/testing/common/testId';
import { createTestItemChildren, ExtHostTestItemEvent, ITestChildrenLike, ITestItemApi, ITestItemChildren, TestItemCollection, TestItemEventOp } from 'vs/workbench/contrib/testing/common/testItemCollection';
import { ITestItem } from 'vs/workbench/contrib/testing/common/testTypes';
import { denamespaceTestTag, ITestItem, ITestItemContext } from 'vs/workbench/contrib/testing/common/testTypes';
import type * as vscode from 'vscode';
import * as Convert from 'vs/workbench/api/common/extHostTypeConverters';
import { URI } from 'vs/base/common/uri';
const testItemPropAccessor = <K extends keyof vscode.TestItem>(
api: IExtHostTestItemApi,
@@ -83,6 +84,27 @@ const makePropDescriptors = (api: IExtHostTestItemApi, label: string): { [K in k
})),
});
const toItemFromPlain = (item: ITestItem.Serialized): TestItemImpl => {
const testId = TestId.fromString(item.extId);
const testItem = new TestItemImpl(testId.controllerId, testId.localId, item.label, URI.revive(item.uri) || undefined);
testItem.range = Convert.Range.to(item.range || undefined);
testItem.description = item.description || undefined;
testItem.sortText = item.sortText || undefined;
testItem.tags = item.tags.map(t => Convert.TestTag.to({ id: denamespaceTestTag(t).tagId }));
return testItem;
};
export const toItemFromContext = (context: ITestItemContext): TestItemImpl => {
let node: TestItemImpl | undefined;
for (const test of context.tests) {
const next = toItemFromPlain(test.item);
getPrivateApiFor(next).parent = node;
node = next;
}
return node!;
};
export class TestItemImpl implements vscode.TestItem {
public readonly id!: string;
public readonly uri!: vscode.Uri | undefined;