22/* eslint-disable @typescript-eslint/no-explicit-any */
33import * as TypeMoq from 'typemoq' ;
44import * as sinon from 'sinon' ;
5- import { Disposable } from 'vscode' ;
5+ import { Disposable , ExtensionContext } from 'vscode' ;
66import { expect } from 'chai' ;
77
88import { IInterpreterService } from '../../client/interpreter/contracts' ;
99import { PythonEnvironment } from '../../client/pythonEnvironments/info' ;
10- import { getNativeRepl , NativeRepl } from '../../client/repl/nativeRepl' ;
10+ import { getNativeRepl , NATIVE_REPL_URI_MEMENTO , NativeRepl } from '../../client/repl/nativeRepl' ;
1111import { IExtensionContext } from '../../client/common/types' ;
12+ import * as replUtils from '../../client/repl/replUtils' ;
1213
1314suite ( 'REPL - Native REPL' , ( ) => {
1415 let interpreterService : TypeMoq . IMock < IInterpreterService > ;
1516 let extensionContext : TypeMoq . IMock < IExtensionContext > ;
1617 let disposable : TypeMoq . IMock < Disposable > ;
1718 let disposableArray : Disposable [ ] = [ ] ;
18-
1919 let setReplDirectoryStub : sinon . SinonStub ;
2020 let setReplControllerSpy : sinon . SinonSpy ;
21-
21+ let memento : TypeMoq . IMock < ExtensionContext [ 'globalState' ] > ;
22+ let getTabNameForUriStub : sinon . SinonStub ;
2223 setup ( ( ) => {
2324 interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
2425 interpreterService
2526 . setup ( ( i ) => i . getActiveInterpreter ( TypeMoq . It . isAny ( ) ) )
2627 . returns ( ( ) => Promise . resolve ( ( { path : 'ps' } as unknown ) as PythonEnvironment ) ) ;
2728 disposable = TypeMoq . Mock . ofType < Disposable > ( ) ;
2829 disposableArray = [ disposable . object ] ;
29-
30+ memento = TypeMoq . Mock . ofType < ExtensionContext [ 'globalState' ] > ( ) ;
3031 setReplDirectoryStub = sinon . stub ( NativeRepl . prototype as any , 'setReplDirectory' ) . resolves ( ) ; // Stubbing private method
3132 // Use a spy instead of a stub for setReplController
33+ getTabNameForUriStub = sinon . stub ( replUtils , 'getTabNameForUri' ) . returns ( 'tabName' ) ;
3234 setReplControllerSpy = sinon . spy ( NativeRepl . prototype , 'setReplController' ) ;
3335 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 ) ;
3438 } ) ;
3539
3640 teardown ( ( ) => {
@@ -39,9 +43,10 @@ suite('REPL - Native REPL', () => {
3943 d . dispose ( ) ;
4044 }
4145 } ) ;
42-
4346 disposableArray = [ ] ;
4447 sinon . restore ( ) ;
48+ extensionContext ?. reset ( ) ;
49+ memento ?. reset ( ) ;
4550 } ) ;
4651
4752 test ( 'getNativeRepl should call create constructor' , async ( ) => {
@@ -55,6 +60,24 @@ suite('REPL - Native REPL', () => {
5560 expect ( createMethodStub . calledOnce ) . to . be . true ;
5661 } ) ;
5762
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+
66+ interpreterService
67+ . setup ( ( i ) => i . getActiveInterpreter ( TypeMoq . It . isAny ( ) ) )
68+ . returns ( ( ) => Promise . resolve ( ( { path : 'ps' } as unknown ) as PythonEnvironment ) ) ;
69+ const interpreter = await interpreterService . object . getActiveInterpreter ( ) ;
70+ const nativeRepl = await getNativeRepl (
71+ interpreter as PythonEnvironment ,
72+ disposableArray ,
73+ extensionContext . object ,
74+ ) ;
75+
76+ nativeRepl . sendToNativeRepl ( undefined , false ) ;
77+
78+ expect ( getTabNameForUriStub . notCalled ) . to . be . true ;
79+ } ) ;
80+
5881 test ( 'create should call setReplDirectory, setReplController' , async ( ) => {
5982 const interpreter = await interpreterService . object . getActiveInterpreter ( ) ;
6083 interpreterService
0 commit comments