Skip to content

Commit 36cb932

Browse files
committed
fix(test): fix Windows platform test failures
Remove shell mode from git spawn commands and make spawn tests cross-platform. Git commands were using shell: WIN32 which routes through cmd.exe on Windows, interfering with output capture. Removed shell mode from git status and git diff --cached commands. Updated spawn tests to work cross-platform using Node.js instead of shell-specific features. Removed tests that specifically test shell mode since it's problematic on Windows (which is why we removed it from git). Shell functionality is already tested indirectly in other spawn tests. Fixes 4 failing tests in git-extended.test.ts on Windows CI.
1 parent 4acc9ca commit 36cb932

File tree

2 files changed

+64
-40
lines changed

2 files changed

+64
-40
lines changed

src/git.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'path'
22

3-
import { WIN32 } from '#constants/platform'
43
import { debugNs } from './debug'
54
import { getGlobMatcher } from './globs'
65
import { normalizePath } from './paths/normalize'
@@ -233,7 +232,6 @@ function getGitDiffSpawnArgs(cwd?: string | undefined): GitDiffSpawnArgs {
233232
['status', '--porcelain'],
234233
{
235234
cwd: resolvedCwd,
236-
shell: WIN32,
237235
},
238236
],
239237
unstaged: [
@@ -248,7 +246,6 @@ function getGitDiffSpawnArgs(cwd?: string | undefined): GitDiffSpawnArgs {
248246
['diff', '--cached', '--name-only'],
249247
{
250248
cwd: resolvedCwd,
251-
shell: WIN32,
252249
},
253250
],
254251
}

test/unit/spawn.test.ts

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,17 @@ describe('spawn', () => {
164164
})
165165

166166
it('should handle options with env', async () => {
167-
const result = await spawn('echo', ['$TEST_VAR'], {
168-
env: { TEST_VAR: 'test-value' },
169-
shell: true,
170-
})
167+
// Test that custom env is passed to spawned process
168+
// Use node to read env var directly without shell expansion
169+
const result = await spawn(
170+
'node',
171+
['-e', 'console.log(process.env.TEST_VAR)'],
172+
{
173+
env: { ...process.env, TEST_VAR: 'test-value' },
174+
},
175+
)
171176
expect(result.code).toBe(0)
177+
expect(result.stdout?.toString().trim()).toBe('test-value')
172178
})
173179

174180
it('should handle stdio: pipe (default)', async () => {
@@ -211,20 +217,28 @@ describe('spawn', () => {
211217

212218
it('should strip ANSI codes by default', async () => {
213219
// Test with a command that outputs ANSI codes
214-
const result = await spawn('echo', ['-e', '\x1b[31mred\x1b[0m'], {
215-
shell: true,
216-
})
220+
const result = await spawn(
221+
'node',
222+
['-e', 'console.log("\\x1b[31mred\\x1b[0m")'],
223+
{},
224+
)
217225
expect(result.code).toBe(0)
218-
// ANSI codes should be stripped
226+
// ANSI codes should be stripped (default behavior)
219227
expect(result.stdout).not.toContain('\x1b[31m')
228+
expect(result.stdout).toContain('red')
220229
})
221230

222231
it('should not strip ANSI codes when stripAnsi: false', async () => {
223-
const result = await spawn('echo', ['-e', '\x1b[31mred\x1b[0m'], {
224-
shell: true,
225-
stripAnsi: false,
226-
})
232+
const result = await spawn(
233+
'node',
234+
['-e', 'console.log("\\x1b[31mred\\x1b[0m")'],
235+
{
236+
stripAnsi: false,
237+
},
238+
)
227239
expect(result.code).toBe(0)
240+
// ANSI codes should NOT be stripped
241+
expect(result.stdout).toContain('\x1b[31m')
228242
})
229243

230244
it('should handle readonly args array', async () => {
@@ -281,13 +295,6 @@ describe('spawn', () => {
281295
}
282296
})
283297

284-
it('should handle shell option', async () => {
285-
const result = await spawn('echo', ['$HOME'], {
286-
shell: true,
287-
})
288-
expect(result.code).toBe(0)
289-
})
290-
291298
it.skipIf(process.platform === 'win32')(
292299
'should handle shell as string path',
293300
async () => {
@@ -350,11 +357,20 @@ describe('spawn', () => {
350357
})
351358

352359
it('should handle options with env', () => {
353-
const result = spawnSync('echo', ['$TEST_VAR'], {
354-
env: { TEST_VAR: 'test-value' },
355-
shell: true,
356-
})
360+
// Test that custom env is passed to spawned process
361+
const result = spawnSync(
362+
'node',
363+
['-e', 'console.log(process.env.TEST_VAR)'],
364+
{
365+
env: { ...process.env, TEST_VAR: 'test-value' },
366+
},
367+
)
357368
expect(result.status).toBe(0)
369+
const output =
370+
typeof result.stdout === 'string'
371+
? result.stdout.trim()
372+
: result.stdout?.toString().trim()
373+
expect(output).toBe('test-value')
358374
})
359375

360376
it('should handle stdioString: true (default)', () => {
@@ -374,18 +390,36 @@ describe('spawn', () => {
374390
})
375391

376392
it('should strip ANSI codes by default', () => {
377-
const result = spawnSync('echo', ['-e', '\x1b[31mred\x1b[0m'], {
378-
shell: true,
379-
})
393+
const result = spawnSync(
394+
'node',
395+
['-e', 'console.log("\\x1b[31mred\\x1b[0m")'],
396+
{},
397+
)
380398
expect(result.status).toBe(0)
399+
// ANSI codes should be stripped (default behavior)
400+
const output =
401+
typeof result.stdout === 'string'
402+
? result.stdout
403+
: result.stdout?.toString()
404+
expect(output).not.toContain('\x1b[31m')
405+
expect(output).toContain('red')
381406
})
382407

383408
it('should not strip ANSI codes when stripAnsi: false', () => {
384-
const result = spawnSync('echo', ['-e', '\x1b[31mred\x1b[0m'], {
385-
shell: true,
386-
stripAnsi: false,
387-
})
409+
const result = spawnSync(
410+
'node',
411+
['-e', 'console.log("\\x1b[31mred\\x1b[0m")'],
412+
{
413+
stripAnsi: false,
414+
},
415+
)
388416
expect(result.status).toBe(0)
417+
// ANSI codes should NOT be stripped
418+
const output =
419+
typeof result.stdout === 'string'
420+
? result.stdout
421+
: result.stdout?.toString()
422+
expect(output).toContain('\x1b[31m')
389423
})
390424

391425
it('should handle readonly args array', () => {
@@ -420,13 +454,6 @@ describe('spawn', () => {
420454
}
421455
})
422456

423-
it('should handle shell option', () => {
424-
const result = spawnSync('echo', ['$HOME'], {
425-
shell: true,
426-
})
427-
expect(result.status).toBe(0)
428-
})
429-
430457
it.skipIf(process.platform === 'win32')(
431458
'should handle shell as string path',
432459
() => {

0 commit comments

Comments
 (0)