1- import { execSync } from 'child_process' ;
1+ import { execFileSync } from 'child_process' ;
22import {
33 beforeEach ,
44 describe ,
@@ -14,9 +14,13 @@ import { clearGitCache } from '../../utils/git';
1414import { renderOsc8Link } from '../../utils/hyperlink' ;
1515import { GitBranchWidget } from '../GitBranch' ;
1616
17- vi . mock ( 'child_process' , ( ) => ( { execSync : vi . fn ( ) } ) ) ;
17+ vi . mock ( 'child_process' , ( ) => ( {
18+ execSync : vi . fn ( ) ,
19+ execFileSync : vi . fn ( ) ,
20+ spawnSync : vi . fn ( )
21+ } ) ) ;
1822
19- const mockExecSync = execSync as unknown as {
23+ const mockExecFileSync = execFileSync as unknown as {
2024 mock : { calls : unknown [ ] [ ] } ;
2125 mockImplementation : ( impl : ( ) => never ) => void ;
2226 mockReturnValue : ( value : string ) => void ;
@@ -66,33 +70,37 @@ describe('GitBranchWidget', () => {
6670 } ) ;
6771
6872 it ( 'should render branch name' , ( ) => {
69- mockExecSync . mockReturnValueOnce ( 'true\n' ) ;
70- mockExecSync . mockReturnValueOnce ( 'feature/worktree' ) ;
73+ mockExecFileSync . mockReturnValueOnce ( 'true\n' ) ;
74+ mockExecFileSync . mockReturnValueOnce ( 'feature/worktree' ) ;
7175
7276 expect ( render ( { cwd : '/tmp/worktree' } ) ) . toBe ( '⎇ feature/worktree' ) ;
73- expect ( mockExecSync . mock . calls [ 0 ] ?. [ 1 ] ) . toEqual ( {
77+ expect ( mockExecFileSync . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( 'git' ) ;
78+ expect ( mockExecFileSync . mock . calls [ 0 ] ?. [ 1 ] ) . toEqual ( [ 'rev-parse' , '--is-inside-work-tree' ] ) ;
79+ expect ( mockExecFileSync . mock . calls [ 0 ] ?. [ 2 ] ) . toEqual ( {
7480 encoding : 'utf8' ,
7581 stdio : [ 'pipe' , 'pipe' , 'ignore' ] ,
7682 cwd : '/tmp/worktree'
7783 } ) ;
78- expect ( mockExecSync . mock . calls [ 1 ] ?. [ 1 ] ) . toEqual ( {
84+ expect ( mockExecFileSync . mock . calls [ 1 ] ?. [ 0 ] ) . toBe ( 'git' ) ;
85+ expect ( mockExecFileSync . mock . calls [ 1 ] ?. [ 1 ] ) . toEqual ( [ 'branch' , '--show-current' ] ) ;
86+ expect ( mockExecFileSync . mock . calls [ 1 ] ?. [ 2 ] ) . toEqual ( {
7987 encoding : 'utf8' ,
8088 stdio : [ 'pipe' , 'pipe' , 'ignore' ] ,
8189 cwd : '/tmp/worktree'
8290 } ) ;
8391 } ) ;
8492
8593 it ( 'should render raw branch value' , ( ) => {
86- mockExecSync . mockReturnValueOnce ( 'true\n' ) ;
87- mockExecSync . mockReturnValueOnce ( 'feature/worktree' ) ;
94+ mockExecFileSync . mockReturnValueOnce ( 'true\n' ) ;
95+ mockExecFileSync . mockReturnValueOnce ( 'feature/worktree' ) ;
8896
8997 expect ( render ( { rawValue : true } ) ) . toBe ( 'feature/worktree' ) ;
9098 } ) ;
9199
92100 it ( 'should render encoded GitHub branch links' , ( ) => {
93- mockExecSync . mockReturnValueOnce ( 'true\n' ) ;
94- mockExecSync . mockReturnValueOnce ( 'feature/issue#1' ) ;
95- mockExecSync . mockReturnValueOnce ( 'ssh://git@github.com/owner/repo.git' ) ;
101+ mockExecFileSync . mockReturnValueOnce ( 'true\n' ) ;
102+ mockExecFileSync . mockReturnValueOnce ( 'feature/issue#1' ) ;
103+ mockExecFileSync . mockReturnValueOnce ( 'ssh://git@github.com/owner/repo.git' ) ;
96104
97105 expect ( render ( { linkToGitHub : true } ) ) . toBe ( renderOsc8Link (
98106 'https://github.com/owner/repo/tree/feature/issue%231' ,
@@ -101,34 +109,34 @@ describe('GitBranchWidget', () => {
101109 } ) ;
102110
103111 it ( 'should render no git when probe returns false' , ( ) => {
104- mockExecSync . mockReturnValue ( 'false\n' ) ;
112+ mockExecFileSync . mockReturnValue ( 'false\n' ) ;
105113
106114 expect ( render ( ) ) . toBe ( '⎇ no git' ) ;
107115 } ) ;
108116
109117 it ( 'should hide no git when configured' , ( ) => {
110- mockExecSync . mockReturnValue ( 'false\n' ) ;
118+ mockExecFileSync . mockReturnValue ( 'false\n' ) ;
111119
112120 expect ( render ( { hideNoGit : true } ) ) . toBeNull ( ) ;
113121 } ) ;
114122
115123 it ( 'should render no git when branch lookup is empty' , ( ) => {
116- mockExecSync . mockReturnValueOnce ( 'true\n' ) ;
117- mockExecSync . mockReturnValueOnce ( '' ) ;
124+ mockExecFileSync . mockReturnValueOnce ( 'true\n' ) ;
125+ mockExecFileSync . mockReturnValueOnce ( '' ) ;
118126
119127 expect ( render ( ) ) . toBe ( '⎇ no git' ) ;
120128 } ) ;
121129
122130 it ( 'should render no git when command fails' , ( ) => {
123- mockExecSync . mockImplementation ( ( ) => { throw new Error ( 'No git' ) ; } ) ;
131+ mockExecFileSync . mockImplementation ( ( ) => { throw new Error ( 'No git' ) ; } ) ;
124132
125133 expect ( render ( ) ) . toBe ( '⎇ no git' ) ;
126134 } ) ;
127135
128136 it ( 'should keep plain text when GitHub remote cannot be parsed' , ( ) => {
129- mockExecSync . mockReturnValueOnce ( 'true\n' ) ;
130- mockExecSync . mockReturnValueOnce ( 'feature/worktree' ) ;
131- mockExecSync . mockReturnValueOnce ( 'https://gitlab.com/owner/repo.git' ) ;
137+ mockExecFileSync . mockReturnValueOnce ( 'true\n' ) ;
138+ mockExecFileSync . mockReturnValueOnce ( 'feature/worktree' ) ;
139+ mockExecFileSync . mockReturnValueOnce ( 'https://gitlab.com/owner/repo.git' ) ;
132140
133141 expect ( render ( { linkToGitHub : true } ) ) . toBe ( '⎇ feature/worktree' ) ;
134142 } ) ;
0 commit comments