Skip to content

Commit 18e829a

Browse files
dorlugasigalCopilot
andcommitted
fix(test): mock os.platform in ps-based shell detection tests
The 'should use detected shell when ps returns a known shell' and 'should fall back when ps command fails' tests assumed Unix platform. On Windows CI, getDefaultShell() takes the win32 branch (wmic) instead of the ps branch, causing the ps mock to be ignored. Fix: mock os.platform() to return 'linux' so the Unix code path is always exercised regardless of the CI runner's actual platform. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 430f4bb commit 18e829a

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test/cli.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,11 @@ describe('CLI', () => {
425425

426426
describe('getDefaultShell edge cases', () => {
427427
it('should fall back when ps command fails', () => {
428+
const os = require('os');
428429
const child_process = require('child_process');
430+
const origPlatform = os.platform;
429431
const origExecFileSync = child_process.execFileSync;
432+
os.platform = () => 'linux';
430433
child_process.execFileSync = (cmd, ...args) => {
431434
if (cmd === 'ps') throw new Error('ps not available');
432435
return origExecFileSync(cmd, ...args);
@@ -438,13 +441,17 @@ describe('CLI', () => {
438441
const config = parseArgs();
439442
assert.ok(config.defaultShell, 'Should have a fallback shell');
440443
} finally {
444+
os.platform = origPlatform;
441445
child_process.execFileSync = origExecFileSync;
442446
}
443447
});
444448

445449
it('should use detected shell when ps returns a known shell', () => {
450+
const os = require('os');
446451
const child_process = require('child_process');
452+
const origPlatform = os.platform;
447453
const origExecFileSync = child_process.execFileSync;
454+
os.platform = () => 'linux';
448455
child_process.execFileSync = (cmd, args, opts) => {
449456
if (cmd === 'ps') return 'bash\n';
450457
return origExecFileSync(cmd, args, opts);
@@ -456,6 +463,7 @@ describe('CLI', () => {
456463
const config = parseArgs();
457464
assert.strictEqual(config.defaultShell, 'bash');
458465
} finally {
466+
os.platform = origPlatform;
459467
child_process.execFileSync = origExecFileSync;
460468
}
461469
});

0 commit comments

Comments
 (0)