Skip to content

Commit c53f99b

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 8cb9c93 commit c53f99b

File tree

1 file changed

+82
-86
lines changed

1 file changed

+82
-86
lines changed

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

Lines changed: 82 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// // Copyright (c) Microsoft Corporation. All rights reserved.
2-
// // Licensed under the MIT License.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
33

4-
// import * as assert from 'assert';
5-
// import * as sinon from 'sinon';
6-
// import * as typemoq from 'typemoq';
4+
import * as assert from 'assert';
5+
import * as sinon from 'sinon';
6+
import * as typemoq from 'typemoq';
77

88
import { TestController, TestItem, TestItemCollection, TestRun, Uri } from 'vscode';
99
import { IConfigurationService, ITestOutputChannel } from '../../../client/common/types';
@@ -23,15 +23,15 @@ suite('Workspace test adapter', () => {
2323
let stubConfigSettings: IConfigurationService;
2424
let stubResultResolver: ITestResultResolver;
2525

26-
// let discoverTestsStub: sinon.SinonStub;
27-
// let sendTelemetryStub: sinon.SinonStub;
28-
// let outputChannel: typemoq.IMock<ITestOutputChannel>;
26+
let discoverTestsStub: sinon.SinonStub;
27+
let sendTelemetryStub: sinon.SinonStub;
28+
let outputChannel: typemoq.IMock<ITestOutputChannel>;
2929

30-
// let telemetryEvent: { eventName: EventName; properties: Record<string, unknown> }[] = [];
30+
let telemetryEvent: { eventName: EventName; properties: Record<string, unknown> }[] = [];
3131

32-
// // Stubbed test controller (see comment around L.40)
33-
// let testController: TestController;
34-
// let log: string[] = [];
32+
// Stubbed test controller (see comment around L.40)
33+
let testController: TestController;
34+
let log: string[] = [];
3535

3636
setup(() => {
3737
stubConfigSettings = ({
@@ -75,34 +75,46 @@ suite('Workspace test adapter', () => {
7575
},
7676
} as unknown) as TestItem;
7777

78-
// stubResultResolver = ({
79-
// resolveDiscovery: () => {
80-
// // no body
81-
// },
82-
// resolveExecution: () => {
83-
// // no body
84-
// },
85-
// vsIdToRunId: {
86-
// get: sinon.stub().returns('expectedRunId'),
87-
// },
88-
// } as unknown) as ITestResultResolver;
89-
90-
// // const vsIdToRunIdGetStub = sinon.stub(stubResultResolver.vsIdToRunId, 'get');
91-
// // const expectedRunId = 'expectedRunId';
92-
// // vsIdToRunIdGetStub.withArgs(sinon.match.any).returns(expectedRunId);
93-
94-
// // For some reason the 'tests' namespace in vscode returns undefined.
95-
// // While I figure out how to expose to the tests, they will run
96-
// // against a stub test controller and stub test items.
97-
// const testItem = ({
98-
// canResolveChildren: false,
99-
// tags: [],
100-
// children: {
101-
// add: () => {
102-
// // empty
103-
// },
104-
// },
105-
// } as unknown) as TestItem;
78+
// const vsIdToRunIdGetStub = sinon.stub(stubResultResolver.vsIdToRunId, 'get');
79+
// const expectedRunId = 'expectedRunId';
80+
// vsIdToRunIdGetStub.withArgs(sinon.match.any).returns(expectedRunId);
81+
82+
// For some reason the 'tests' namespace in vscode returns undefined.
83+
// While I figure out how to expose to the tests, they will run
84+
// against a stub test controller and stub test items.
85+
const testItem = ({
86+
canResolveChildren: false,
87+
tags: [],
88+
children: {
89+
add: () => {
90+
// empty
91+
},
92+
},
93+
} as unknown) as TestItem;
94+
95+
testController = ({
96+
items: {
97+
get: () => {
98+
log.push('get');
99+
},
100+
add: () => {
101+
log.push('add');
102+
},
103+
replace: () => {
104+
log.push('replace');
105+
},
106+
delete: () => {
107+
log.push('delete');
108+
},
109+
},
110+
createTestItem: () => {
111+
log.push('createTestItem');
112+
return testItem;
113+
},
114+
dispose: () => {
115+
// empty
116+
},
117+
} as unknown) as TestController;
106118

107119
discoverTestsStub = sinon.stub(UnittestTestDiscoveryAdapter.prototype, 'discoverTests');
108120
sendTelemetryStub = sinon.stub(Telemetry, 'sendTelemetryEvent').callsFake(mockSendTelemetryEvent);
@@ -247,10 +259,12 @@ suite('Workspace test adapter', () => {
247259
sinon.assert.calledWithMatch(buildErrorNodeOptionsStub, Uri.parse('foo'), sinon.match.any, testProvider);
248260
});
249261

250-
// discoverTestsStub = sandbox.stub(UnittestTestDiscoveryAdapter.prototype, 'discoverTests');
251-
// sendTelemetryStub = sandbox.stub(Telemetry, 'sendTelemetryEvent').callsFake(mockSendTelemetryEvent);
252-
// outputChannel = typemoq.Mock.ofType<ITestOutputChannel>();
253-
// });
262+
teardown(() => {
263+
telemetryEvent = [];
264+
log = [];
265+
testController.dispose();
266+
sinon.restore();
267+
});
254268

255269
const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(
256270
stubTestServer,
@@ -270,26 +284,24 @@ suite('Workspace test adapter', () => {
270284
stubResultResolver,
271285
);
272286

273-
// test("When discovering tests, the workspace test adapter should call the test discovery adapter's discoverTest method", async () => {
274-
// discoverTestsStub.resolves();
275-
276-
// const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(
277-
// stubTestServer,
278-
// stubConfigSettings,
279-
// outputChannel.object,
280-
// );
281-
// const testExecutionAdapter = new UnittestTestExecutionAdapter(
282-
// stubTestServer,
283-
// stubConfigSettings,
284-
// outputChannel.object,
285-
// );
286-
// const workspaceTestAdapter = new WorkspaceTestAdapter(
287-
// 'unittest',
288-
// testDiscoveryAdapter,
289-
// testExecutionAdapter,
290-
// Uri.parse('foo'),
291-
// stubResultResolver,
292-
// );
287+
const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(
288+
stubTestServer,
289+
stubConfigSettings,
290+
outputChannel.object,
291+
);
292+
const testExecutionAdapter = new UnittestTestExecutionAdapter(
293+
stubTestServer,
294+
stubConfigSettings,
295+
outputChannel.object,
296+
);
297+
298+
const workspaceTestAdapter = new WorkspaceTestAdapter(
299+
'unittest',
300+
testDiscoveryAdapter,
301+
testExecutionAdapter,
302+
Uri.parse('foo'),
303+
stubResultResolver,
304+
);
293305

294306
const workspaceTestAdapter = new WorkspaceTestAdapter(
295307
'unittest',
@@ -570,32 +582,17 @@ suite('Workspace test adapter', () => {
570582
const one = workspaceTestAdapter.executeTests(testController, runInstance.object, []);
571583
const two = workspaceTestAdapter.executeTests(testController, runInstance.object, []);
572584

573-
// const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(
574-
// stubTestServer,
575-
// stubConfigSettings,
576-
// outputChannel.object,
577-
// );
578-
// const testExecutionAdapter = new UnittestTestExecutionAdapter(
579-
// stubTestServer,
580-
// stubConfigSettings,
581-
// outputChannel.object,
582-
// );
583-
// const workspaceTestAdapter = new WorkspaceTestAdapter(
584-
// 'unittest',
585-
// testDiscoveryAdapter,
586-
// testExecutionAdapter,
587-
// Uri.parse('foo'),
588-
// stubResultResolver,
589-
// );
585+
test("When discovering tests, the workspace test adapter should call the test discovery adapter's discoverTest method", async () => {
586+
discoverTestsStub.resolves();
590587

591588
sinon.assert.calledOnce(executionTestsStub);
592589
});
593590

594591
test('If execution failed correctly create error node', async () => {
595592
executionTestsStub.rejects(new Error('foo'));
596593

597-
// sinon.assert.calledOnce(discoverTestsStub);
598-
// });
594+
sinon.assert.calledOnce(discoverTestsStub);
595+
});
599596

600597
const workspaceTestAdapter = new WorkspaceTestAdapter(
601598
'unittest',
@@ -632,9 +629,8 @@ suite('Workspace test adapter', () => {
632629
test('If execution failed, send a telemetry event with the "failed" key set to true, and add an error node to the test controller', async () => {
633630
executionTestsStub.rejects(new Error('foo'));
634631

635-
// const lastEvent = telemetryEvent[1];
636-
// assert.strictEqual(lastEvent.properties.failed, false);
637-
// });
632+
test('If discovery succeeds, send a telemetry event with the "failed" key set to false', async () => {
633+
discoverTestsStub.resolves({ status: 'success' });
638634

639635
const workspaceTestAdapter = new WorkspaceTestAdapter(
640636
'unittest',

0 commit comments

Comments
 (0)