3
3
4
4
import * as sinon from 'sinon' ;
5
5
import * as TypeMoq from 'typemoq' ;
6
- import { GlobalEnvironmentVariableCollection , Uri , WorkspaceConfiguration } from 'vscode' ;
6
+ import {
7
+ GlobalEnvironmentVariableCollection ,
8
+ Uri ,
9
+ WorkspaceConfiguration ,
10
+ Disposable ,
11
+ CancellationToken ,
12
+ TerminalLinkContext ,
13
+ Terminal ,
14
+ EventEmitter ,
15
+ } from 'vscode' ;
16
+ import { assert } from 'chai' ;
7
17
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis' ;
8
18
import { registerPythonStartup } from '../../../client/terminals/pythonStartup' ;
9
19
import { IExtensionContext } from '../../../client/common/types' ;
20
+ import * as pythonStartupLinkProvider from '../../../client/terminals/pythonStartupLinkProvider' ;
21
+ import { CustomTerminalLinkProvider } from '../../../client/terminals/pythonStartupLinkProvider' ;
22
+ import { Repl } from '../../../client/common/utils/localize' ;
10
23
11
24
suite ( 'Terminal - Shell Integration with PYTHONSTARTUP' , ( ) => {
12
25
let getConfigurationStub : sinon . SinonStub ;
@@ -20,7 +33,6 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
20
33
setup ( ( ) => {
21
34
context = TypeMoq . Mock . ofType < IExtensionContext > ( ) ;
22
35
globalEnvironmentVariableCollection = TypeMoq . Mock . ofType < GlobalEnvironmentVariableCollection > ( ) ;
23
-
24
36
// Question: Why do we have to set up environmentVariableCollection and globalEnvironmentVariableCollection in this flip-flop way?
25
37
// Reference: /vscode-python/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts
26
38
context . setup ( ( c ) => c . environmentVariableCollection ) . returns ( ( ) => globalEnvironmentVariableCollection . object ) ;
@@ -122,4 +134,64 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
122
134
123
135
globalEnvironmentVariableCollection . verify ( ( c ) => c . delete ( 'PYTHONSTARTUP' ) , TypeMoq . Times . once ( ) ) ;
124
136
} ) ;
137
+
138
+ test ( 'Ensure registering terminal link calls registerTerminalLinkProvider' , async ( ) => {
139
+ const registerTerminalLinkProviderStub = sinon . stub (
140
+ pythonStartupLinkProvider ,
141
+ 'registerCustomTerminalLinkProvider' ,
142
+ ) ;
143
+ const disposableArray : Disposable [ ] = [ ] ;
144
+ pythonStartupLinkProvider . registerCustomTerminalLinkProvider ( disposableArray ) ;
145
+
146
+ sinon . assert . calledOnce ( registerTerminalLinkProviderStub ) ;
147
+ sinon . assert . calledWith ( registerTerminalLinkProviderStub , disposableArray ) ;
148
+
149
+ registerTerminalLinkProviderStub . restore ( ) ;
150
+ } ) ;
151
+
152
+ test ( 'Verify provideTerminalLinks returns links when context.line contains expectedNativeLink' , ( ) => {
153
+ const provider = new CustomTerminalLinkProvider ( ) ;
154
+ const context : TerminalLinkContext = {
155
+ line : 'Some random string with VS Code Native REPL in it' ,
156
+ terminal : { } as Terminal ,
157
+ } ;
158
+ const token : CancellationToken = {
159
+ isCancellationRequested : false ,
160
+ onCancellationRequested : new EventEmitter < unknown > ( ) . event ,
161
+ } ;
162
+
163
+ const links = provider . provideTerminalLinks ( context , token ) ;
164
+
165
+ assert . isNotNull ( links , 'Expected links to be not undefined' ) ;
166
+ assert . isArray ( links , 'Expected links to be an array' ) ;
167
+ assert . isNotEmpty ( links , 'Expected links to be not empty' ) ;
168
+
169
+ if ( Array . isArray ( links ) ) {
170
+ assert . equal ( links [ 0 ] . command , 'python.startNativeREPL' , 'Expected command to be python.startNativeREPL' ) ;
171
+ assert . equal (
172
+ links [ 0 ] . startIndex ,
173
+ context . line . indexOf ( 'VS Code Native REPL' ) ,
174
+ 'Expected startIndex to be 0' ,
175
+ ) ;
176
+ assert . equal ( links [ 0 ] . length , 'VS Code Native REPL' . length , 'Expected length to be 16' ) ;
177
+ assert . equal ( links [ 0 ] . tooltip , Repl . launchNativeRepl , 'Expected tooltip to be Launch VS Code Native REPL' ) ;
178
+ }
179
+ } ) ;
180
+
181
+ test ( 'Verify provideTerminalLinks returns no links when context.line does not contain expectedNativeLink' , ( ) => {
182
+ const provider = new CustomTerminalLinkProvider ( ) ;
183
+ const context : TerminalLinkContext = {
184
+ line : 'Some random string without the expected link' ,
185
+ terminal : { } as Terminal ,
186
+ } ;
187
+ const token : CancellationToken = {
188
+ isCancellationRequested : false ,
189
+ onCancellationRequested : new EventEmitter < unknown > ( ) . event ,
190
+ } ;
191
+
192
+ const links = provider . provideTerminalLinks ( context , token ) ;
193
+
194
+ assert . isArray ( links , 'Expected links to be an array' ) ;
195
+ assert . isEmpty ( links , 'Expected links to be empty' ) ;
196
+ } ) ;
125
197
} ) ;
0 commit comments