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.
3
3
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' ;
7
7
8
8
import { TestController , TestItem , TestItemCollection , TestRun , Uri } from 'vscode' ;
9
9
import { IConfigurationService , ITestOutputChannel } from '../../../client/common/types' ;
@@ -23,15 +23,15 @@ suite('Workspace test adapter', () => {
23
23
let stubConfigSettings : IConfigurationService ;
24
24
let stubResultResolver : ITestResultResolver ;
25
25
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 > ;
29
29
30
- // let telemetryEvent: { eventName: EventName; properties: Record<string, unknown> }[] = [];
30
+ let telemetryEvent : { eventName : EventName ; properties : Record < string , unknown > } [ ] = [ ] ;
31
31
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 [ ] = [ ] ;
35
35
36
36
setup ( ( ) => {
37
37
stubConfigSettings = ( {
@@ -75,34 +75,46 @@ suite('Workspace test adapter', () => {
75
75
} ,
76
76
} as unknown ) as TestItem ;
77
77
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 ;
106
118
107
119
discoverTestsStub = sinon . stub ( UnittestTestDiscoveryAdapter . prototype , 'discoverTests' ) ;
108
120
sendTelemetryStub = sinon . stub ( Telemetry , 'sendTelemetryEvent' ) . callsFake ( mockSendTelemetryEvent ) ;
@@ -247,10 +259,12 @@ suite('Workspace test adapter', () => {
247
259
sinon . assert . calledWithMatch ( buildErrorNodeOptionsStub , Uri . parse ( 'foo' ) , sinon . match . any , testProvider ) ;
248
260
} ) ;
249
261
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
+ } ) ;
254
268
255
269
const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter (
256
270
stubTestServer ,
@@ -270,26 +284,24 @@ suite('Workspace test adapter', () => {
270
284
stubResultResolver ,
271
285
) ;
272
286
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
+ ) ;
293
305
294
306
const workspaceTestAdapter = new WorkspaceTestAdapter (
295
307
'unittest' ,
@@ -570,32 +582,17 @@ suite('Workspace test adapter', () => {
570
582
const one = workspaceTestAdapter . executeTests ( testController , runInstance . object , [ ] ) ;
571
583
const two = workspaceTestAdapter . executeTests ( testController , runInstance . object , [ ] ) ;
572
584
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 ( ) ;
590
587
591
588
sinon . assert . calledOnce ( executionTestsStub ) ;
592
589
} ) ;
593
590
594
591
test ( 'If execution failed correctly create error node' , async ( ) => {
595
592
executionTestsStub . rejects ( new Error ( 'foo' ) ) ;
596
593
597
- // sinon.assert.calledOnce(discoverTestsStub);
598
- // });
594
+ sinon . assert . calledOnce ( discoverTestsStub ) ;
595
+ } ) ;
599
596
600
597
const workspaceTestAdapter = new WorkspaceTestAdapter (
601
598
'unittest' ,
@@ -632,9 +629,8 @@ suite('Workspace test adapter', () => {
632
629
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 ( ) => {
633
630
executionTestsStub . rejects ( new Error ( 'foo' ) ) ;
634
631
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' } ) ;
638
634
639
635
const workspaceTestAdapter = new WorkspaceTestAdapter (
640
636
'unittest' ,
0 commit comments