Skip to content

Commit 4a278e7

Browse files
committed
tests
1 parent 48c8686 commit 4a278e7

File tree

2 files changed

+271
-261
lines changed

2 files changed

+271
-261
lines changed

src/test/repl/nativeRepl.test.ts

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,72 @@
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';
77

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';
1112

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[] = [];
1418

15-
// let disposable: TypeMoq.IMock<Disposable>;
16-
// let disposableArray: Disposable[] = [];
19+
let setReplDirectoryStub: sinon.SinonStub;
20+
let setReplControllerSpy: sinon.SinonSpy;
1721

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];
2029

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+
});
2835

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+
});
3342

34-
// teardown(() => {
35-
// disposableArray.forEach((d) => {
36-
// if (d) {
37-
// d.dispose();
38-
// }
39-
// });
43+
disposableArray = [];
44+
sinon.restore();
45+
});
4046

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);
4454

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+
});
5257

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));
5563

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);
6165

62-
// await NativeRepl.create(interpreter as PythonEnvironment);
66+
expect(setReplDirectoryStub.calledOnce).to.be.true;
67+
expect(setReplControllerSpy.calledOnce).to.be.true;
6368

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

Comments
 (0)