Skip to content

Commit 9677628

Browse files
committed
adding tests for execution
1 parent 978f7e6 commit 9677628

File tree

3 files changed

+73
-142
lines changed

3 files changed

+73
-142
lines changed

src/client/testing/testController/unittest/testExecutionAdapter.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,9 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
7777
this.promiseMap.set(uuid, deferred);
7878
traceLog(`Running UNITTEST execution for the following test ids: ${testIds}`);
7979

80-
let runTestIdsPort: string | undefined;
81-
await startTestIdServer(testIds)
82-
.then((assignedPort) => {
83-
traceLog(`Server started and listening on port ${assignedPort}`);
84-
runTestIdsPort = assignedPort.toString();
85-
// Send test command to server.
86-
// Server fire onDataReceived event once it gets response.
87-
})
88-
.catch((error) => {
89-
traceError('Error starting server:', error);
90-
});
80+
const runTestIdsPort = await startTestIdServer(testIds);
9181

92-
await this.testServer.sendCommand(options, runTestIdsPort, () => {
82+
await this.testServer.sendCommand(options, runTestIdsPort.toString(), () => {
9383
// disposable.dispose();
9484
deferred.resolve();
9585
});

src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ suite('pytest test execution adapter', () => {
2525
let execService: typeMoq.IMock<IPythonExecutionService>;
2626
let deferred: Deferred<void>;
2727
let debugLauncher: typeMoq.IMock<ITestDebugLauncher>;
28-
// let startTestIdServerMock = typeMoq.Mock.ofType<typeof util.startTestIdServer>();
29-
// let startTestIdServer: sinon.SinonStub;
30-
const startTestIdServer = sinon.stub(util, 'startTestIdServer');
31-
startTestIdServer.returns(Promise.resolve(12344));
3228

3329
setup(() => {
3430
testServer = typeMoq.Mock.ofType<ITestServer>();
@@ -65,19 +61,18 @@ suite('pytest test execution adapter', () => {
6561
deferred.resolve();
6662
return Promise.resolve();
6763
});
64+
sinon.stub(util, 'startTestIdServer').returns(Promise.resolve(54321));
65+
6866
execFactory.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
6967
execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
7068
debugLauncher.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
71-
// startTestIdServerMock = typeMoq.Mock.ofType<typeof util.startTestIdServer>();
72-
// startTestIdServerMock.setup(() => typeMoq.It.isAny()).returns(async () => 12345);
73-
// startTestIdServerMock = typeMoq.Mock.ofInstance(util.startTestIdServer);
74-
// startTestIdServerMock.setup((x) => x(typeMoq.It.isAny())).returns(async () => 12345);
75-
// util.startTestIdServer = startTestIdServerMock.object;
69+
});
70+
teardown(() => {
71+
sinon.restore();
7672
});
7773
test('pytest execution called with correct args', async () => {
7874
const uri = Uri.file('/my/test/path/');
7975
const uuid = 'uuid123';
80-
// const data = { status: 'success' };
8176
testServer
8277
.setup((t) => t.onDiscoveryDataReceived(typeMoq.It.isAny(), typeMoq.It.isAny()))
8378
.returns(() => ({
@@ -109,7 +104,7 @@ suite('pytest test execution adapter', () => {
109104
assert.equal(options.extraVariables?.PYTHONPATH, expectedExtraVariables.PYTHONPATH);
110105
assert.equal(options.extraVariables?.TEST_UUID, expectedExtraVariables.TEST_UUID);
111106
assert.equal(options.extraVariables?.TEST_PORT, expectedExtraVariables.TEST_PORT);
112-
assert.strictEqual(typeof options.extraVariables?.RUN_TEST_IDS_PORT, 'string');
107+
assert.equal(options.extraVariables?.RUN_TEST_IDS_PORT, '54321');
113108
assert.equal(options.cwd, uri.fsPath);
114109
assert.equal(options.throwOnStdErr, true);
115110
return true;
@@ -142,7 +137,7 @@ suite('pytest test execution adapter', () => {
142137
assert.equal(launchOptions.testProvider, 'pytest');
143138
assert.equal(launchOptions.pytestPort, '12345');
144139
assert.equal(launchOptions.pytestUUID, 'uuid123');
145-
assert.strictEqual(typeof launchOptions.runTestIdsPort, 'string');
140+
assert.strictEqual(launchOptions.runTestIdsPort, '54321');
146141
return true;
147142
}),
148143
typeMoq.It.isAny(),
Lines changed: 64 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,64 @@
1-
// // Copyright (c) Microsoft Corporation. All rights reserved.
2-
// // Licensed under the MIT License.
3-
4-
// import * as assert from 'assert';
5-
// import * as path from 'path';
6-
// import * as typemoq from 'typemoq';
7-
// import { Uri } from 'vscode';
8-
// import { IConfigurationService, ITestOutputChannel } from '../../../../client/common/types';
9-
// import { EXTENSION_ROOT_DIR } from '../../../../client/constants';
10-
// import { ITestServer, TestCommandOptions } from '../../../../client/testing/testController/common/types';
11-
// import { UnittestTestExecutionAdapter } from '../../../../client/testing/testController/unittest/testExecutionAdapter';
12-
13-
// suite('Unittest test execution adapter', () => {
14-
// let stubConfigSettings: IConfigurationService;
15-
// let outputChannel: typemoq.IMock<ITestOutputChannel>;
16-
17-
// setup(() => {
18-
// stubConfigSettings = ({
19-
// getSettings: () => ({
20-
// testing: { unittestArgs: ['-v', '-s', '.', '-p', 'test*'] },
21-
// }),
22-
// } as unknown) as IConfigurationService;
23-
// outputChannel = typemoq.Mock.ofType<ITestOutputChannel>();
24-
// });
25-
26-
// test('runTests should send the run command to the test server', async () => {
27-
// let options: TestCommandOptions | undefined;
28-
29-
// const stubTestServer = ({
30-
// sendCommand(opt: TestCommandOptions, runTestIdPort?: string): Promise<void> {
31-
// delete opt.outChannel;
32-
// options = opt;
33-
// assert(runTestIdPort !== undefined);
34-
// return Promise.resolve();
35-
// },
36-
// onDataReceived: () => {
37-
// // no body
38-
// },
39-
// createUUID: () => '123456789',
40-
// } as unknown) as ITestServer;
41-
42-
// const uri = Uri.file('/foo/bar');
43-
// const script = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'unittestadapter', 'execution.py');
44-
45-
// const adapter = new UnittestTestExecutionAdapter(stubTestServer, stubConfigSettings, outputChannel.object);
46-
// adapter.runTests(uri, [], false).then(() => {
47-
// const expectedOptions: TestCommandOptions = {
48-
// workspaceFolder: uri,
49-
// command: { script, args: ['--udiscovery', '-v', '-s', '.', '-p', 'test*'] },
50-
// cwd: uri.fsPath,
51-
// uuid: '123456789',
52-
// debugBool: false,
53-
// testIds: [],
54-
// };
55-
// assert.deepStrictEqual(options, expectedOptions);
56-
// });
57-
// });
58-
// test("onDataReceivedHandler should parse the data if the cwd from the payload matches the test adapter's cwd", async () => {
59-
// const stubTestServer = ({
60-
// sendCommand(): Promise<void> {
61-
// return Promise.resolve();
62-
// },
63-
// onDataReceived: () => {
64-
// // no body
65-
// },
66-
// createUUID: () => '123456789',
67-
// } as unknown) as ITestServer;
68-
69-
// const uri = Uri.file('/foo/bar');
70-
// const data = { status: 'success' };
71-
// const uuid = '123456789';
72-
73-
// const adapter = new UnittestTestExecutionAdapter(stubTestServer, stubConfigSettings, outputChannel.object);
74-
75-
// // triggers runTests flow which will run onDataReceivedHandler and the
76-
// // promise resolves into the parsed data.
77-
// const promise = adapter.runTests(uri, [], false);
78-
79-
// adapter.onDataReceivedHandler({ uuid, data: JSON.stringify(data) });
80-
81-
// const result = await promise;
82-
83-
// assert.deepStrictEqual(result, data);
84-
// });
85-
// test("onDataReceivedHandler should ignore the data if the cwd from the payload does not match the test adapter's cwd", async () => {
86-
// const correctUuid = '123456789';
87-
// const incorrectUuid = '987654321';
88-
// const stubTestServer = ({
89-
// sendCommand(): Promise<void> {
90-
// return Promise.resolve();
91-
// },
92-
// onDataReceived: () => {
93-
// // no body
94-
// },
95-
// createUUID: () => correctUuid,
96-
// } as unknown) as ITestServer;
97-
98-
// const uri = Uri.file('/foo/bar');
99-
100-
// const adapter = new UnittestTestExecutionAdapter(stubTestServer, stubConfigSettings, outputChannel.object);
101-
102-
// // triggers runTests flow which will run onDataReceivedHandler and the
103-
// // promise resolves into the parsed data.
104-
// const promise = adapter.runTests(uri, [], false);
105-
106-
// const data = { status: 'success' };
107-
// // will not resolve due to incorrect UUID
108-
// adapter.onDataReceivedHandler({ uuid: incorrectUuid, data: JSON.stringify(data) });
109-
110-
// const nextData = { status: 'error' };
111-
// // will resolve and nextData will be returned as result
112-
// adapter.onDataReceivedHandler({ uuid: correctUuid, data: JSON.stringify(nextData) });
113-
114-
// const result = await promise;
115-
116-
// assert.deepStrictEqual(result, nextData);
117-
// });
118-
// });
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import * as assert from 'assert';
5+
import * as path from 'path';
6+
import * as typemoq from 'typemoq';
7+
import { Uri } from 'vscode';
8+
import * as sinon from 'sinon';
9+
import { IConfigurationService, ITestOutputChannel } from '../../../../client/common/types';
10+
import { EXTENSION_ROOT_DIR } from '../../../../client/constants';
11+
import { ITestServer, TestCommandOptions } from '../../../../client/testing/testController/common/types';
12+
import { UnittestTestExecutionAdapter } from '../../../../client/testing/testController/unittest/testExecutionAdapter';
13+
import * as util from '../../../../client/testing/testController/common/utils';
14+
15+
suite('Unittest test execution adapter', () => {
16+
let stubConfigSettings: IConfigurationService;
17+
let outputChannel: typemoq.IMock<ITestOutputChannel>;
18+
19+
setup(() => {
20+
stubConfigSettings = ({
21+
getSettings: () => ({
22+
testing: { unittestArgs: ['-v', '-s', '.', '-p', 'test*'] },
23+
}),
24+
} as unknown) as IConfigurationService;
25+
outputChannel = typemoq.Mock.ofType<ITestOutputChannel>();
26+
sinon.stub(util, 'startTestIdServer').returns(Promise.resolve(54321));
27+
});
28+
teardown(() => {
29+
sinon.restore();
30+
});
31+
32+
test('runTests should send the run command to the test server', async () => {
33+
let options: TestCommandOptions | undefined;
34+
35+
const stubTestServer = ({
36+
sendCommand(opt: TestCommandOptions, runTestIdPort?: string): Promise<void> {
37+
delete opt.outChannel;
38+
options = opt;
39+
assert(runTestIdPort !== undefined);
40+
return Promise.resolve();
41+
},
42+
onRunDataReceived: () => {
43+
// no body
44+
},
45+
createUUID: () => '123456789',
46+
} as unknown) as ITestServer;
47+
48+
const uri = Uri.file('/foo/bar');
49+
const script = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'unittestadapter', 'execution.py');
50+
51+
const adapter = new UnittestTestExecutionAdapter(stubTestServer, stubConfigSettings, outputChannel.object);
52+
adapter.runTests(uri, [], false).then(() => {
53+
const expectedOptions: TestCommandOptions = {
54+
workspaceFolder: uri,
55+
command: { script, args: ['--udiscovery', '-v', '-s', '.', '-p', 'test*'] },
56+
cwd: uri.fsPath,
57+
uuid: '123456789',
58+
debugBool: false,
59+
testIds: [],
60+
};
61+
assert.deepStrictEqual(options, expectedOptions);
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)