22/* eslint-disable @typescript-eslint/no-explicit-any */
33import * as TypeMoq from 'typemoq' ;
44import * as sinon from 'sinon' ;
5- import { Disposable , ExtensionContext } from 'vscode' ;
5+ import { Disposable } from 'vscode' ;
66import { expect } from 'chai' ;
77
88import { IInterpreterService } from '../../client/interpreter/contracts' ;
99import { PythonEnvironment } from '../../client/pythonEnvironments/info' ;
10- import { getNativeRepl , NATIVE_REPL_URI_MEMENTO , NativeRepl } from '../../client/repl/nativeRepl' ;
11- import { IExtensionContext } from '../../client/common/types' ;
10+ import { getNativeRepl , NativeRepl } from '../../client/repl/nativeRepl' ;
11+
1212import * as replUtils from '../../client/repl/replUtils' ;
13+ import * as persistentState from '../../client/common/persistentState' ;
1314
1415suite ( 'REPL - Native REPL' , ( ) => {
1516 let interpreterService : TypeMoq . IMock < IInterpreterService > ;
16- let extensionContext : TypeMoq . IMock < IExtensionContext > ;
17+
1718 let disposable : TypeMoq . IMock < Disposable > ;
1819 let disposableArray : Disposable [ ] = [ ] ;
1920 let setReplDirectoryStub : sinon . SinonStub ;
2021 let setReplControllerSpy : sinon . SinonSpy ;
21- let memento : TypeMoq . IMock < ExtensionContext [ 'globalState' ] > ;
22- let getTabNameForUriStub : sinon . SinonStub ;
22+ let getWorkspaceStateValueStub : sinon . SinonStub ;
23+
2324 setup ( ( ) => {
2425 interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
2526 interpreterService
2627 . setup ( ( i ) => i . getActiveInterpreter ( TypeMoq . It . isAny ( ) ) )
2728 . returns ( ( ) => Promise . resolve ( ( { path : 'ps' } as unknown ) as PythonEnvironment ) ) ;
2829 disposable = TypeMoq . Mock . ofType < Disposable > ( ) ;
2930 disposableArray = [ disposable . object ] ;
30- memento = TypeMoq . Mock . ofType < ExtensionContext [ 'globalState' ] > ( ) ;
31+
3132 setReplDirectoryStub = sinon . stub ( NativeRepl . prototype as any , 'setReplDirectory' ) . resolves ( ) ; // Stubbing private method
3233 // Use a spy instead of a stub for setReplController
33- getTabNameForUriStub = sinon . stub ( replUtils , 'getTabNameForUri' ) . returns ( 'tabName' ) ;
3434 setReplControllerSpy = sinon . spy ( NativeRepl . prototype , 'setReplController' ) ;
35- extensionContext = TypeMoq . Mock . ofType < IExtensionContext > ( ) ;
36- extensionContext . setup ( ( c ) => c . globalState ) . returns ( ( ) => memento . object ) ;
37- memento . setup ( ( m ) => m . get ( NATIVE_REPL_URI_MEMENTO ) ) . returns ( ( ) => undefined ) ;
35+ getWorkspaceStateValueStub = sinon . stub ( persistentState , 'getWorkspaceStateValue' ) . returns ( undefined ) ;
3836 } ) ;
3937
4038 teardown ( ( ) => {
@@ -45,8 +43,6 @@ suite('REPL - Native REPL', () => {
4543 } ) ;
4644 disposableArray = [ ] ;
4745 sinon . restore ( ) ;
48- extensionContext ?. reset ( ) ;
49- memento ?. reset ( ) ;
5046 } ) ;
5147
5248 test ( 'getNativeRepl should call create constructor' , async ( ) => {
@@ -60,9 +56,7 @@ suite('REPL - Native REPL', () => {
6056 expect ( createMethodStub . calledOnce ) . to . be . true ;
6157 } ) ;
6258
63- test ( 'sendToNativeRepl with undefined URI should not try to reload' , async ( ) => {
64- memento . setup ( ( m ) => m . get ( NATIVE_REPL_URI_MEMENTO ) ) . returns ( ( ) => undefined ) ;
65-
59+ test ( 'sendToNativeRepl should look for memento URI if notebook document is undefined' , async ( ) => {
6660 interpreterService
6761 . setup ( ( i ) => i . getActiveInterpreter ( TypeMoq . It . isAny ( ) ) )
6862 . returns ( ( ) => Promise . resolve ( ( { path : 'ps' } as unknown ) as PythonEnvironment ) ) ;
@@ -71,7 +65,7 @@ suite('REPL - Native REPL', () => {
7165
7266 nativeRepl . sendToNativeRepl ( undefined , false ) ;
7367
74- expect ( getTabNameForUriStub . notCalled ) . to . be . true ;
68+ expect ( getWorkspaceStateValueStub . calledOnce ) . to . be . true ;
7569 } ) ;
7670
7771 test ( 'create should call setReplDirectory, setReplController' , async ( ) => {
0 commit comments