Skip to content

Commit 932dc39

Browse files
committed
Workspace & resolver tests (microsoft#21441)
This PR - moves populateTestTree to utils - adds tests for execution adapters (pytest and unittest) - resultResolver tests - workspaceTestAdapater tests
1 parent b84fb74 commit 932dc39

File tree

1 file changed

+66
-0
lines changed
  • src/client/testing/testController/common

1 file changed

+66
-0
lines changed

src/client/testing/testController/common/utils.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,69 @@ export function populateTestTree(
188188
function isTestItem(test: DiscoveredTestNode | DiscoveredTestItem): test is DiscoveredTestItem {
189189
return test.type_ === 'test';
190190
}
191+
192+
export function buildErrorNodeOptions(uri: Uri, message: string, testType: string): ErrorTestItemOptions {
193+
const labelText = testType === 'pytest' ? 'Pytest Discovery Error' : 'Unittest Discovery Error';
194+
return {
195+
id: `DiscoveryError:${uri.fsPath}`,
196+
label: `${labelText} [${path.basename(uri.fsPath)}]`,
197+
error: message,
198+
};
199+
}
200+
201+
export function populateTestTree(
202+
testController: TestController,
203+
testTreeData: DiscoveredTestNode,
204+
testRoot: TestItem | undefined,
205+
resultResolver: ITestResultResolver,
206+
token?: CancellationToken,
207+
): void {
208+
// If testRoot is undefined, use the info of the root item of testTreeData to create a test item, and append it to the test controller.
209+
if (!testRoot) {
210+
testRoot = testController.createTestItem(testTreeData.path, testTreeData.name, Uri.file(testTreeData.path));
211+
212+
testRoot.canResolveChildren = true;
213+
testRoot.tags = [RunTestTag, DebugTestTag];
214+
215+
testController.items.add(testRoot);
216+
}
217+
218+
// Recursively populate the tree with test data.
219+
testTreeData.children.forEach((child) => {
220+
if (!token?.isCancellationRequested) {
221+
if (isTestItem(child)) {
222+
const testItem = testController.createTestItem(child.id_, child.name, Uri.file(child.path));
223+
testItem.tags = [RunTestTag, DebugTestTag];
224+
225+
const range = new Range(
226+
new Position(Number(child.lineno) - 1, 0),
227+
new Position(Number(child.lineno), 0),
228+
);
229+
testItem.canResolveChildren = false;
230+
testItem.range = range;
231+
testItem.tags = [RunTestTag, DebugTestTag];
232+
233+
testRoot!.children.add(testItem);
234+
// add to our map
235+
resultResolver.runIdToTestItem.set(child.runID, testItem);
236+
resultResolver.runIdToVSid.set(child.runID, child.id_);
237+
resultResolver.vsIdToRunId.set(child.id_, child.runID);
238+
} else {
239+
let node = testController.items.get(child.path);
240+
241+
if (!node) {
242+
node = testController.createTestItem(child.id_, child.name, Uri.file(child.path));
243+
244+
node.canResolveChildren = true;
245+
node.tags = [RunTestTag, DebugTestTag];
246+
testRoot!.children.add(node);
247+
}
248+
populateTestTree(testController, child, node, resultResolver, token);
249+
}
250+
}
251+
});
252+
}
253+
254+
function isTestItem(test: DiscoveredTestNode | DiscoveredTestItem): test is DiscoveredTestItem {
255+
return test.type_ === 'test';
256+
}

0 commit comments

Comments
 (0)