11// npx vitest run src/integrations/terminal/__tests__/TerminalProfile.spec.ts
22
3+ import { existsSync } from "fs"
4+
35import * as vscode from "vscode"
46
57import { Terminal } from "../Terminal"
@@ -9,6 +11,12 @@ vi.mock("execa", () => ({
911 execa : vi . fn ( ) ,
1012} ) )
1113
14+ vi . mock ( "fs" , ( ) => ( {
15+ existsSync : vi . fn ( ( ) => false ) ,
16+ } ) )
17+
18+ const mockedExistsSync = existsSync as unknown as ReturnType < typeof vi . fn >
19+
1220describe ( "Terminal inline terminal profile (#119)" , ( ) => {
1321 // VS Code's getConfiguration/createTerminal are overloaded, so the precise
1422 // spy MockInstance type isn't worth fighting in a test — `any` keeps it simple.
@@ -44,6 +52,9 @@ describe("Terminal inline terminal profile (#119)", () => {
4452
4553 beforeEach ( ( ) => {
4654 createTerminalSpy = vi . spyOn ( vscode . window , "createTerminal" ) . mockImplementation ( ( ) => mockTerminal ( ) )
55+ // Default: no candidate path exists on disk unless a test says otherwise.
56+ mockedExistsSync . mockReset ( )
57+ mockedExistsSync . mockReturnValue ( false )
4758 // Reset to default (unset) before each test.
4859 Terminal . setTerminalProfile ( undefined )
4960 } )
@@ -117,14 +128,34 @@ describe("Terminal inline terminal profile (#119)", () => {
117128 } )
118129 } )
119130
120- it ( "uses the first path candidate when path is an array" , ( ) => {
131+ it ( "picks the first existing path candidate when path is an array" , ( ) => {
121132 stubProfiles ( {
122133 windows : {
123134 "Git Bash" : {
124135 path : [ "C:\\missing\\bash.exe" , "C:\\Program Files\\Git\\bin\\bash.exe" ] ,
125136 } ,
126137 } ,
127138 } )
139+ // Only the second candidate exists on disk; VS Code would pick it.
140+ mockedExistsSync . mockImplementation ( ( p : string ) => p === "C:\\Program Files\\Git\\bin\\bash.exe" )
141+
142+ Terminal . setTerminalProfile ( "Git Bash" )
143+
144+ expect ( Terminal . getProfileShell ( "win32" ) ) . toEqual ( {
145+ shellPath : "C:\\Program Files\\Git\\bin\\bash.exe" ,
146+ shellArgs : undefined ,
147+ } )
148+ } )
149+
150+ it ( "falls back to the first non-empty candidate when none of the paths exist" , ( ) => {
151+ stubProfiles ( {
152+ windows : {
153+ "Git Bash" : {
154+ path : [ "C:\\missing\\bash.exe" , "C:\\also-missing\\bash.exe" ] ,
155+ } ,
156+ } ,
157+ } )
158+ // existsSync defaults to false for every candidate.
128159
129160 Terminal . setTerminalProfile ( "Git Bash" )
130161
0 commit comments