|
1 | | -// /* eslint-disable no-unused-expressions */ |
2 | | -// /* eslint-disable @typescript-eslint/no-explicit-any */ |
3 | | -// import * as TypeMoq from 'typemoq'; |
4 | | -// import * as sinon from 'sinon'; |
5 | | -// import { Disposable } from 'vscode'; |
6 | | -// import { expect } from 'chai'; |
| 1 | +/* eslint-disable no-unused-expressions */ |
| 2 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 3 | +import * as TypeMoq from 'typemoq'; |
| 4 | +import * as sinon from 'sinon'; |
| 5 | +import { Disposable } from 'vscode'; |
| 6 | +import { expect } from 'chai'; |
7 | 7 |
|
8 | | -// import { IInterpreterService } from '../../client/interpreter/contracts'; |
9 | | -// import { PythonEnvironment } from '../../client/pythonEnvironments/info'; |
10 | | -// import { getNativeRepl, NativeRepl } from '../../client/repl/nativeRepl'; |
| 8 | +import { IInterpreterService } from '../../client/interpreter/contracts'; |
| 9 | +import { PythonEnvironment } from '../../client/pythonEnvironments/info'; |
| 10 | +import { getNativeRepl, NativeRepl } from '../../client/repl/nativeRepl'; |
| 11 | +import { IExtensionContext } from '../../client/common/types'; |
11 | 12 |
|
12 | | -// suite('REPL - Native REPL', () => { |
13 | | -// let interpreterService: TypeMoq.IMock<IInterpreterService>; |
| 13 | +suite('REPL - Native REPL', () => { |
| 14 | + let interpreterService: TypeMoq.IMock<IInterpreterService>; |
| 15 | + let extensionContext: TypeMoq.IMock<IExtensionContext>; |
| 16 | + let disposable: TypeMoq.IMock<Disposable>; |
| 17 | + let disposableArray: Disposable[] = []; |
14 | 18 |
|
15 | | -// let disposable: TypeMoq.IMock<Disposable>; |
16 | | -// let disposableArray: Disposable[] = []; |
| 19 | + let setReplDirectoryStub: sinon.SinonStub; |
| 20 | + let setReplControllerSpy: sinon.SinonSpy; |
17 | 21 |
|
18 | | -// let setReplDirectoryStub: sinon.SinonStub; |
19 | | -// let setReplControllerSpy: sinon.SinonSpy; |
| 22 | + setup(() => { |
| 23 | + interpreterService = TypeMoq.Mock.ofType<IInterpreterService>(); |
| 24 | + interpreterService |
| 25 | + .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) |
| 26 | + .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); |
| 27 | + disposable = TypeMoq.Mock.ofType<Disposable>(); |
| 28 | + disposableArray = [disposable.object]; |
20 | 29 |
|
21 | | -// setup(() => { |
22 | | -// interpreterService = TypeMoq.Mock.ofType<IInterpreterService>(); |
23 | | -// interpreterService |
24 | | -// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) |
25 | | -// .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); |
26 | | -// disposable = TypeMoq.Mock.ofType<Disposable>(); |
27 | | -// disposableArray = [disposable.object]; |
| 30 | + setReplDirectoryStub = sinon.stub(NativeRepl.prototype as any, 'setReplDirectory').resolves(); // Stubbing private method |
| 31 | + // Use a spy instead of a stub for setReplController |
| 32 | + setReplControllerSpy = sinon.spy(NativeRepl.prototype, 'setReplController'); |
| 33 | + extensionContext = TypeMoq.Mock.ofType<IExtensionContext>(); |
| 34 | + }); |
28 | 35 |
|
29 | | -// setReplDirectoryStub = sinon.stub(NativeRepl.prototype as any, 'setReplDirectory').resolves(); // Stubbing private method |
30 | | -// // Use a spy instead of a stub for setReplController |
31 | | -// setReplControllerSpy = sinon.spy(NativeRepl.prototype, 'setReplController'); |
32 | | -// }); |
| 36 | + teardown(() => { |
| 37 | + disposableArray.forEach((d) => { |
| 38 | + if (d) { |
| 39 | + d.dispose(); |
| 40 | + } |
| 41 | + }); |
33 | 42 |
|
34 | | -// teardown(() => { |
35 | | -// disposableArray.forEach((d) => { |
36 | | -// if (d) { |
37 | | -// d.dispose(); |
38 | | -// } |
39 | | -// }); |
| 43 | + disposableArray = []; |
| 44 | + sinon.restore(); |
| 45 | + }); |
40 | 46 |
|
41 | | -// disposableArray = []; |
42 | | -// sinon.restore(); |
43 | | -// }); |
| 47 | + test('getNativeRepl should call create constructor', async () => { |
| 48 | + const createMethodStub = sinon.stub(NativeRepl, 'create'); |
| 49 | + interpreterService |
| 50 | + .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) |
| 51 | + .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); |
| 52 | + const interpreter = await interpreterService.object.getActiveInterpreter(); |
| 53 | + await getNativeRepl(interpreter as PythonEnvironment, disposableArray, extensionContext.object); |
44 | 54 |
|
45 | | -// test('getNativeRepl should call create constructor', async () => { |
46 | | -// const createMethodStub = sinon.stub(NativeRepl, 'create'); |
47 | | -// interpreterService |
48 | | -// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) |
49 | | -// .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); |
50 | | -// const interpreter = await interpreterService.object.getActiveInterpreter(); |
51 | | -// await getNativeRepl(interpreter as PythonEnvironment, disposableArray); |
| 55 | + expect(createMethodStub.calledOnce).to.be.true; |
| 56 | + }); |
52 | 57 |
|
53 | | -// expect(createMethodStub.calledOnce).to.be.true; |
54 | | -// }); |
| 58 | + test('create should call setReplDirectory, setReplController', async () => { |
| 59 | + const interpreter = await interpreterService.object.getActiveInterpreter(); |
| 60 | + interpreterService |
| 61 | + .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) |
| 62 | + .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); |
55 | 63 |
|
56 | | -// test('create should call setReplDirectory, setReplController', async () => { |
57 | | -// const interpreter = await interpreterService.object.getActiveInterpreter(); |
58 | | -// interpreterService |
59 | | -// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) |
60 | | -// .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); |
| 64 | + await NativeRepl.create(interpreter as PythonEnvironment, extensionContext.object); |
61 | 65 |
|
62 | | -// await NativeRepl.create(interpreter as PythonEnvironment); |
| 66 | + expect(setReplDirectoryStub.calledOnce).to.be.true; |
| 67 | + expect(setReplControllerSpy.calledOnce).to.be.true; |
63 | 68 |
|
64 | | -// expect(setReplDirectoryStub.calledOnce).to.be.true; |
65 | | -// expect(setReplControllerSpy.calledOnce).to.be.true; |
66 | | - |
67 | | -// setReplDirectoryStub.restore(); |
68 | | -// setReplControllerSpy.restore(); |
69 | | -// }); |
70 | | -// }); |
| 69 | + setReplDirectoryStub.restore(); |
| 70 | + setReplControllerSpy.restore(); |
| 71 | + }); |
| 72 | +}); |
0 commit comments