|
| 1 | +// /* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 | +// // Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +// // Licensed under the MIT License. |
| 4 | +// import * as assert from 'assert'; |
| 5 | +// import { Uri } from 'vscode'; |
| 6 | +// import * as typeMoq from 'typemoq'; |
| 7 | +// import { IConfigurationService } from '../../../../client/common/types'; |
| 8 | +// import { DataReceivedEvent, ITestServer } from '../../../../client/testing/testController/common/types'; |
| 9 | +// import { IPythonExecutionFactory, IPythonExecutionService } from '../../../../client/common/process/types'; |
| 10 | +// import { createDeferred, Deferred } from '../../../../client/common/utils/async'; |
| 11 | +// import { PytestTestExecutionAdapter } from '../../../../client/testing/testController/pytest/pytestExecutionAdapter'; |
| 12 | + |
| 13 | +// suite('pytest test execution adapter', () => { |
| 14 | +// let testServer: typeMoq.IMock<ITestServer>; |
| 15 | +// let configService: IConfigurationService; |
| 16 | +// let execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>(); |
| 17 | +// let adapter: PytestTestExecutionAdapter; |
| 18 | +// let execService: typeMoq.IMock<IPythonExecutionService>; |
| 19 | +// let deferred: Deferred<void>; |
| 20 | +// setup(() => { |
| 21 | +// testServer = typeMoq.Mock.ofType<ITestServer>(); |
| 22 | +// testServer.setup((t) => t.getPort()).returns(() => 12345); |
| 23 | +// testServer |
| 24 | +// .setup((t) => t.onDataReceived(typeMoq.It.isAny(), typeMoq.It.isAny())) |
| 25 | +// .returns(() => ({ |
| 26 | +// dispose: () => { |
| 27 | +// /* no-body */ |
| 28 | +// }, |
| 29 | +// })); |
| 30 | +// configService = ({ |
| 31 | +// getSettings: () => ({ |
| 32 | +// testing: { pytestArgs: ['.'] }, |
| 33 | +// }), |
| 34 | +// isTestExecution: () => false, |
| 35 | +// } as unknown) as IConfigurationService; |
| 36 | +// execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>(); |
| 37 | +// execService = typeMoq.Mock.ofType<IPythonExecutionService>(); |
| 38 | +// execFactory |
| 39 | +// .setup((x) => x.createActivatedEnvironment(typeMoq.It.isAny())) |
| 40 | +// .returns(() => Promise.resolve(execService.object)); |
| 41 | +// deferred = createDeferred(); |
| 42 | +// execService |
| 43 | +// .setup((x) => x.exec(typeMoq.It.isAny(), typeMoq.It.isAny())) |
| 44 | +// .returns(() => { |
| 45 | +// deferred.resolve(); |
| 46 | +// return Promise.resolve({ stdout: '{}' }); |
| 47 | +// }); |
| 48 | +// execFactory.setup((p) => ((p as unknown) as any).then).returns(() => undefined); |
| 49 | +// execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined); |
| 50 | +// }); |
| 51 | +// test('onDataReceivedHandler should parse only if known UUID', async () => { |
| 52 | +// const uri = Uri.file('/my/test/path/'); |
| 53 | +// const uuid = 'uuid123'; |
| 54 | +// const data = { status: 'success' }; |
| 55 | +// testServer.setup((t) => t.createUUID(typeMoq.It.isAny())).returns(() => uuid); |
| 56 | +// const eventData: DataReceivedEvent = { |
| 57 | +// uuid, |
| 58 | +// data: JSON.stringify(data), |
| 59 | +// }; |
| 60 | + |
| 61 | +// adapter = new PytestTestExecutionAdapter(testServer.object, configService); |
| 62 | +// const promise = adapter.runTests(uri, [], false); |
| 63 | +// await deferred.promise; |
| 64 | +// adapter.onDataReceivedHandler(eventData); |
| 65 | +// const result = await promise; |
| 66 | +// assert.deepStrictEqual(result, data); |
| 67 | +// }); |
| 68 | +// test('onDataReceivedHandler should not parse if it is unknown UUID', async () => { |
| 69 | +// const uri = Uri.file('/my/test/path/'); |
| 70 | +// const uuid = 'uuid456'; |
| 71 | +// let data = { status: 'error' }; |
| 72 | +// testServer.setup((t) => t.createUUID(typeMoq.It.isAny())).returns(() => uuid); |
| 73 | +// const wrongUriEventData: DataReceivedEvent = { |
| 74 | +// uuid: 'incorrect-uuid456', |
| 75 | +// data: JSON.stringify(data), |
| 76 | +// }; |
| 77 | +// adapter = new PytestTestExecutionAdapter(testServer.object, configService); |
| 78 | +// const promise = adapter.runTests(uri, [], false); |
| 79 | +// adapter.onDataReceivedHandler(wrongUriEventData); |
| 80 | + |
| 81 | +// data = { status: 'success' }; |
| 82 | +// const correctUriEventData: DataReceivedEvent = { |
| 83 | +// uuid, |
| 84 | +// data: JSON.stringify(data), |
| 85 | +// }; |
| 86 | +// adapter.onDataReceivedHandler(correctUriEventData); |
| 87 | +// const result = await promise; |
| 88 | +// assert.deepStrictEqual(result, data); |
| 89 | +// }); |
| 90 | +// }); |
0 commit comments