|
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 { 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 | +// }); |
0 commit comments