Skip to content

Commit 773ccb1

Browse files
committed
fix failing tests
1 parent 5a831e3 commit 773ccb1

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

src/test/testing/testController/resultResolver.unit.test.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ suite('Result Resolver tests', () => {
9393
// assert the stub functions were called with the correct parameters
9494

9595
// header of populateTestTree is (testController: TestController, testTreeData: DiscoveredTestNode, testRoot: TestItem | undefined, resultResolver: ITestResultResolver, token?: CancellationToken)
96+
// After refactor, an inline object with testItemIndex maps is passed instead of resultResolver
9697
sinon.assert.calledWithMatch(
9798
populateTestTreeStub,
9899
testController, // testController
99100
tests, // testTreeData
100101
undefined, // testRoot
101-
resultResolver, // resultResolver
102+
sinon.match.has('runIdToTestItem'), // inline object with maps
102103
cancelationToken, // token
103104
);
104105
});
@@ -182,12 +183,13 @@ suite('Result Resolver tests', () => {
182183
sinon.assert.calledWithMatch(createErrorTestItemStub, sinon.match.any, sinon.match.any);
183184

184185
// also calls populateTestTree with the discovery test results
186+
// After refactor, an inline object with testItemIndex maps is passed instead of resultResolver
185187
sinon.assert.calledWithMatch(
186188
populateTestTreeStub,
187189
testController, // testController
188190
tests, // testTreeData
189191
undefined, // testRoot
190-
resultResolver, // resultResolver
192+
sinon.match.has('runIdToTestItem'), // inline object with maps
191193
cancelationToken, // token
192194
);
193195
});
@@ -327,20 +329,51 @@ suite('Result Resolver tests', () => {
327329
sinon.stub(testItemUtilities, 'clearAllChildren').callsFake(() => undefined);
328330
testProvider = 'unittest';
329331
workspaceUri = Uri.file('/foo/bar');
332+
333+
// Create parent test item with correct ID
334+
const mockParentItem = createMockTestItem('parentTest');
335+
336+
// Update testControllerMock to include parent item in its collection
337+
const mockTestItems: [string, TestItem][] = [
338+
['1', mockTestItem1],
339+
['2', mockTestItem2],
340+
['parentTest', mockParentItem],
341+
];
342+
const iterableMock = mockTestItems[Symbol.iterator]();
343+
344+
const testItemCollectionMock = typemoq.Mock.ofType<TestItemCollection>();
345+
testItemCollectionMock
346+
.setup((x) => x.forEach(typemoq.It.isAny()))
347+
.callback((callback) => {
348+
let result = iterableMock.next();
349+
while (!result.done) {
350+
callback(result.value[1]);
351+
result = iterableMock.next();
352+
}
353+
})
354+
.returns(() => mockTestItem1);
355+
testItemCollectionMock.setup((x) => x.get('parentTest')).returns(() => mockParentItem);
356+
357+
testControllerMock.reset();
358+
testControllerMock.setup((t) => t.items).returns(() => testItemCollectionMock.object);
359+
330360
resultResolver = new ResultResolver.PythonResultResolver(
331361
testControllerMock.object,
332362
testProvider,
333363
workspaceUri,
334364
);
335365
const subtestName = 'parentTest [subTest with spaces and [brackets]]';
336366
const mockSubtestItem = createMockTestItem(subtestName);
367+
337368
// add a mock test item to the map of known VSCode ids to run ids
338369
resultResolver.runIdToVSid.set('mockTestItem2', 'mockTestItem2');
339370
// creates a mock test item with a space which will be used to split the runId
340371
resultResolver.runIdToVSid.set(subtestName, subtestName);
372+
// Register parent test in testItemIndex so it can be found by getTestItem
373+
resultResolver.runIdToVSid.set('parentTest', 'parentTest');
341374

342375
// add this mock test to the map of known test items
343-
resultResolver.runIdToTestItem.set('parentTest', mockTestItem2);
376+
resultResolver.runIdToTestItem.set('parentTest', mockParentItem);
344377
resultResolver.runIdToTestItem.set(subtestName, mockSubtestItem);
345378

346379
let generatedId: string | undefined;
@@ -563,15 +596,15 @@ suite('Result Resolver tests', () => {
563596

564597
function createMockTestItem(id: string): TestItem {
565598
const range = new Range(0, 0, 0, 0);
599+
const mockChildren = typemoq.Mock.ofType<TestItemCollection>();
600+
mockChildren.setup((x) => x.add(typemoq.It.isAny())).returns(() => undefined);
601+
mockChildren.setup((x) => x.forEach(typemoq.It.isAny())).returns(() => undefined);
602+
566603
const mockTestItem = ({
567604
id,
568605
canResolveChildren: false,
569606
tags: [],
570-
children: {
571-
add: () => {
572-
// empty
573-
},
574-
},
607+
children: mockChildren.object,
575608
range,
576609
uri: Uri.file('/foo/bar'),
577610
} as unknown) as TestItem;

0 commit comments

Comments
 (0)