@@ -6,6 +6,7 @@ import * as assert from "assert";
66import Sinon from "sinon" ;
77import * as vscode from "vscode" ;
88import type { DocumentSelector } from "vscode-languageclient" ;
9+ import { PowerShellProcess } from "../../src/process" ;
910import {
1011 type IPowerShellVersionDetails ,
1112 SessionManager ,
@@ -200,6 +201,89 @@ describe("SessionManager.getVersionDetails", () => {
200201 } ) ;
201202} ) ;
202203
204+ describe ( "SessionManager.restartSession" , ( ) => {
205+ afterEach ( ( ) => {
206+ Sinon . restore ( ) ;
207+ } ) ;
208+
209+ it ( "re-shows the terminal after restart when it was active in background mode" , async ( ) => {
210+ const manager = makeManager ( ) ;
211+ const oldProcess = stubInterface < PowerShellProcess > ( {
212+ isTerminalActive : ( ) => true ,
213+ } ) ;
214+ const showTerminal = Sinon . spy ( ) ;
215+ const newProcess = stubInterface < PowerShellProcess > ( {
216+ showTerminal,
217+ } ) ;
218+ (
219+ manager as unknown as { languageServerProcess : PowerShellProcess }
220+ ) . languageServerProcess = oldProcess ;
221+
222+ Sinon . stub ( vscode . workspace , "getConfiguration" ) . returns (
223+ stubInterface < vscode . WorkspaceConfiguration > ( {
224+ get : < T > ( _section : string ) : T => true as T ,
225+ } ) ,
226+ ) ;
227+ Sinon . stub ( manager as unknown as { stop ( ) : Promise < void > } , "stop" )
228+ . resolves ( ) ;
229+ Sinon . stub ( manager as unknown as { start ( ) : Promise < void > } , "start" )
230+ . callsFake ( async ( ) => {
231+ (
232+ manager as unknown as {
233+ languageServerProcess : PowerShellProcess ;
234+ }
235+ ) . languageServerProcess = newProcess ;
236+ } ) ;
237+
238+ await (
239+ manager as unknown as {
240+ restartSession ( ) : Promise < void > ;
241+ }
242+ ) . restartSession ( ) ;
243+
244+ assert . strictEqual ( showTerminal . callCount , 1 ) ;
245+ assert . deepStrictEqual ( showTerminal . firstCall . args , [ true ] ) ;
246+ } ) ;
247+
248+ it ( "keeps the terminal hidden after restart when it was not active in background mode" , async ( ) => {
249+ const manager = makeManager ( ) ;
250+ const oldProcess = stubInterface < PowerShellProcess > ( {
251+ isTerminalActive : ( ) => false ,
252+ } ) ;
253+ const showTerminal = Sinon . spy ( ) ;
254+ const newProcess = stubInterface < PowerShellProcess > ( {
255+ showTerminal,
256+ } ) ;
257+ (
258+ manager as unknown as { languageServerProcess : PowerShellProcess }
259+ ) . languageServerProcess = oldProcess ;
260+
261+ Sinon . stub ( vscode . workspace , "getConfiguration" ) . returns (
262+ stubInterface < vscode . WorkspaceConfiguration > ( {
263+ get : < T > ( _section : string ) : T => true as T ,
264+ } ) ,
265+ ) ;
266+ Sinon . stub ( manager as unknown as { stop ( ) : Promise < void > } , "stop" )
267+ . resolves ( ) ;
268+ Sinon . stub ( manager as unknown as { start ( ) : Promise < void > } , "start" )
269+ . callsFake ( async ( ) => {
270+ (
271+ manager as unknown as {
272+ languageServerProcess : PowerShellProcess ;
273+ }
274+ ) . languageServerProcess = newProcess ;
275+ } ) ;
276+
277+ await (
278+ manager as unknown as {
279+ restartSession ( ) : Promise < void > ;
280+ }
281+ ) . restartSession ( ) ;
282+
283+ assert . strictEqual ( showTerminal . callCount , 0 ) ;
284+ } ) ;
285+ } ) ;
286+
203287function makeManager ( ) : SessionManager {
204288 Sinon . stub ( vscode . commands , "registerCommand" ) . returns ( disposableStub ( ) ) ;
205289 Sinon . stub ( vscode . workspace , "onDidChangeConfiguration" ) . returns (
0 commit comments