Skip to content

Commit 83ac1c8

Browse files
committed
chore(ci): Fix failing tests
1 parent 8996d8a commit 83ac1c8

15 files changed

Lines changed: 197 additions & 133 deletions

src/utils/__tests__/git-remote.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import {
1818
parseRemoteUrl
1919
} from '../git-remote';
2020

21-
vi.mock('child_process', () => ({ execFileSync: vi.fn() }));
21+
vi.mock('child_process', () => ({
22+
execSync: vi.fn(),
23+
execFileSync: vi.fn(),
24+
spawnSync: vi.fn()
25+
}));
2226

2327
const mockExecFileSync = execFileSync as unknown as {
2428
mock: { calls: unknown[][] };
@@ -386,4 +390,4 @@ describe('git-remote utils', () => {
386390
expect(buildRepoWebUrl(remote)).toBe('https://gitlab.com/group/subgroup/project');
387391
});
388392
});
389-
});
393+
});

src/utils/__tests__/git.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import {
1717
runGit
1818
} from '../git';
1919

20-
vi.mock('child_process', () => ({ execFileSync: vi.fn() }));
20+
vi.mock('child_process', () => ({
21+
execSync: vi.fn(),
22+
execFileSync: vi.fn(),
23+
spawnSync: vi.fn()
24+
}));
2125

2226
const mockExecFileSync = execFileSync as unknown as {
2327
mock: { calls: unknown[][] };
@@ -378,4 +382,4 @@ describe('git utils', () => {
378382
});
379383
});
380384
});
381-
});
385+
});

src/utils/__tests__/open-url.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010

1111
import { openExternalUrl } from '../open-url';
1212

13-
vi.mock('child_process', () => ({ spawnSync: vi.fn() }));
13+
vi.mock('child_process', () => ({
14+
execSync: vi.fn(),
15+
execFileSync: vi.fn(),
16+
spawnSync: vi.fn()
17+
}));
1418

1519
const mockSpawnSync = spawnSync as unknown as {
1620
mock: { calls: unknown[][] };

src/utils/__tests__/terminal.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {
1313
getTerminalWidth
1414
} from '../terminal';
1515

16-
vi.mock('child_process', () => ({ execSync: vi.fn() }));
16+
vi.mock('child_process', () => ({
17+
execSync: vi.fn(),
18+
execFileSync: vi.fn(),
19+
spawnSync: vi.fn()
20+
}));
1721

1822
describe('terminal utils', () => {
1923
const mockExecSync = execSync as unknown as {

src/utils/__tests__/usage-fetch.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { execFileSync } from 'child_process';
1+
import type * as childProcess from 'child_process';
22
import * as fs from 'fs';
3+
import { createRequire } from 'module';
34
import * as os from 'os';
45
import * as path from 'path';
56
import { fileURLToPath } from 'url';
@@ -9,6 +10,9 @@ import {
910
it
1011
} from 'vitest';
1112

13+
const require = createRequire(import.meta.url);
14+
const { execFileSync: realExecFileSync } = require('node:child_process') as { execFileSync: typeof childProcess.execFileSync };
15+
1216
interface UsageProbeResult {
1317
first: Record<string, unknown>;
1418
second: Record<string, unknown>;
@@ -179,7 +183,7 @@ process.stdout.write(JSON.stringify({
179183
}
180184

181185
function runProbe(options: ProbeOptions): UsageProbeResult {
182-
const output = execFileSync(process.execPath, [probeScriptPath], {
186+
const output = realExecFileSync(process.execPath, [probeScriptPath], {
183187
encoding: 'utf8',
184188
env: {
185189
...process.env,

src/utils/__tests__/usage-token-buffer.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212

1313
import { getUsageToken } from '../usage-fetch';
1414

15-
vi.mock('child_process', () => ({ execFileSync: vi.fn() }));
15+
vi.mock('child_process', () => ({
16+
execSync: vi.fn(),
17+
execFileSync: vi.fn(),
18+
spawnSync: vi.fn()
19+
}));
1620

1721
const require = createRequire(import.meta.url);
1822
const { execFileSync: realExecFileSync } = require('node:child_process') as { execFileSync: typeof childProcess.execFileSync };

src/utils/git-remote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ export function listRemotes(context: RenderContext): string[] {
184184
export function buildRepoWebUrl(remote: RemoteInfo): string {
185185
// Assume HTTPS for the web URL
186186
return `https://${remote.host}/${remote.owner}/${remote.repo}`;
187-
}
187+
}

src/utils/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ export function getGitConflictCount(context: RenderContext): number {
174174

175175
export function getGitShortSha(context: RenderContext): string | null {
176176
return runGit('rev-parse --short HEAD', context);
177-
}
177+
}

src/widgets/__tests__/GitBranch.test.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execSync } from 'child_process';
1+
import { execFileSync } from 'child_process';
22
import {
33
beforeEach,
44
describe,
@@ -14,9 +14,13 @@ import { clearGitCache } from '../../utils/git';
1414
import { renderOsc8Link } from '../../utils/hyperlink';
1515
import { 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
});

src/widgets/__tests__/GitChanges.test.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execSync } from 'child_process';
1+
import { execFileSync } from 'child_process';
22
import {
33
beforeEach,
44
describe,
@@ -13,9 +13,13 @@ import type { WidgetItem } from '../../types/Widget';
1313
import { clearGitCache } from '../../utils/git';
1414
import { GitChangesWidget } from '../GitChanges';
1515

16-
vi.mock('child_process', () => ({ execSync: vi.fn() }));
16+
vi.mock('child_process', () => ({
17+
execSync: vi.fn(),
18+
execFileSync: vi.fn(),
19+
spawnSync: vi.fn()
20+
}));
1721

18-
const mockExecSync = execSync as unknown as {
22+
const mockExecFileSync = execFileSync as unknown as {
1923
mock: { calls: unknown[][] };
2024
mockImplementation: (impl: () => never) => void;
2125
mockReturnValue: (value: string) => void;
@@ -52,50 +56,50 @@ describe('GitChangesWidget', () => {
5256
});
5357

5458
it('should render combined staged and unstaged changes', () => {
55-
mockExecSync.mockReturnValueOnce('true\n');
56-
mockExecSync.mockReturnValueOnce('1 file changed, 2 insertions(+), 1 deletion(-)');
57-
mockExecSync.mockReturnValueOnce('1 file changed, 3 insertions(+), 4 deletions(-)');
59+
mockExecFileSync.mockReturnValueOnce('true\n');
60+
mockExecFileSync.mockReturnValueOnce('1 file changed, 2 insertions(+), 1 deletion(-)');
61+
mockExecFileSync.mockReturnValueOnce('1 file changed, 3 insertions(+), 4 deletions(-)');
5862

5963
expect(render({ cwd: '/tmp/worktree' })).toBe('(+5,-5)');
60-
expect(mockExecSync.mock.calls[0]?.[1]).toEqual({
64+
expect(mockExecFileSync.mock.calls[0]?.[2]).toEqual({
6165
encoding: 'utf8',
6266
stdio: ['pipe', 'pipe', 'ignore'],
6367
cwd: '/tmp/worktree'
6468
});
65-
expect(mockExecSync.mock.calls[1]?.[1]).toEqual({
69+
expect(mockExecFileSync.mock.calls[1]?.[2]).toEqual({
6670
encoding: 'utf8',
6771
stdio: ['pipe', 'pipe', 'ignore'],
6872
cwd: '/tmp/worktree'
6973
});
70-
expect(mockExecSync.mock.calls[2]?.[1]).toEqual({
74+
expect(mockExecFileSync.mock.calls[2]?.[2]).toEqual({
7175
encoding: 'utf8',
7276
stdio: ['pipe', 'pipe', 'ignore'],
7377
cwd: '/tmp/worktree'
7478
});
7579
});
7680

7781
it('should render zero counts when repo is clean', () => {
78-
mockExecSync.mockReturnValueOnce('true\n');
79-
mockExecSync.mockReturnValueOnce('');
80-
mockExecSync.mockReturnValueOnce('');
82+
mockExecFileSync.mockReturnValueOnce('true\n');
83+
mockExecFileSync.mockReturnValueOnce('');
84+
mockExecFileSync.mockReturnValueOnce('');
8185

8286
expect(render()).toBe('(+0,-0)');
8387
});
8488

8589
it('should render no git when probe returns false', () => {
86-
mockExecSync.mockReturnValue('false\n');
90+
mockExecFileSync.mockReturnValue('false\n');
8791

8892
expect(render()).toBe('(no git)');
8993
});
9094

9195
it('should hide no git when configured', () => {
92-
mockExecSync.mockReturnValue('false\n');
96+
mockExecFileSync.mockReturnValue('false\n');
9397

9498
expect(render({ hideNoGit: true })).toBeNull();
9599
});
96100

97101
it('should render no git when command fails', () => {
98-
mockExecSync.mockImplementation(() => { throw new Error('No git'); });
102+
mockExecFileSync.mockImplementation(() => { throw new Error('No git'); });
99103

100104
expect(render()).toBe('(no git)');
101105
});

0 commit comments

Comments
 (0)