Skip to content

Commit 287fe6e

Browse files
committed
test(coverage): cover isSocketPyCliInstalled / isSocketBasicsInstalled
Adds direct tests for the two preflight helpers in basics/spawn.mts: - spawn-success exit code 0 → true - spawn-success non-zero code → false - spawn-rejection → false (the catch branches at lines 38 and 54) basics/spawn.mts: 81.98% → 83.78% statements. Remaining gap is inside c8-ignored spinner-only branches.
1 parent e403e49 commit 287fe6e

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

packages/cli/test/unit/utils/basics/spawn.test.mts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ vi.mock('../../../../src/constants.mts', () => ({
7777
DOT_SOCKET_DOT_FACTS_JSON: '.socket.facts.json',
7878
}))
7979

80-
const { runSocketBasics } = await import(
81-
'../../../../src/utils/basics/spawn.mts'
82-
)
80+
const {
81+
isSocketBasicsInstalled,
82+
isSocketPyCliInstalled,
83+
runSocketBasics,
84+
} = await import('../../../../src/utils/basics/spawn.mts')
8385

8486
const baseOpts = {
8587
cwd: '/work',
@@ -501,3 +503,37 @@ describe('runSocketBasics — parseSocketFacts', () => {
501503
}
502504
})
503505
})
506+
507+
describe('isSocketPyCliInstalled', () => {
508+
it('returns true when spawn exits with code 0', async () => {
509+
mockSpawn.mockResolvedValueOnce({ code: 0, stdout: '', stderr: '' })
510+
expect(await isSocketPyCliInstalled('/usr/bin/python3')).toBe(true)
511+
})
512+
513+
it('returns false when spawn exits with non-zero code', async () => {
514+
mockSpawn.mockResolvedValueOnce({ code: 1, stdout: '', stderr: '' })
515+
expect(await isSocketPyCliInstalled('/usr/bin/python3')).toBe(false)
516+
})
517+
518+
it('returns false when spawn rejects (line 38)', async () => {
519+
mockSpawn.mockRejectedValueOnce(new Error('python missing'))
520+
expect(await isSocketPyCliInstalled('/usr/bin/python3')).toBe(false)
521+
})
522+
})
523+
524+
describe('isSocketBasicsInstalled', () => {
525+
it('returns true when spawn exits with code 0', async () => {
526+
mockSpawn.mockResolvedValueOnce({ code: 0, stdout: '', stderr: '' })
527+
expect(await isSocketBasicsInstalled('/usr/bin/python3')).toBe(true)
528+
})
529+
530+
it('returns false when spawn exits with non-zero code', async () => {
531+
mockSpawn.mockResolvedValueOnce({ code: 1, stdout: '', stderr: '' })
532+
expect(await isSocketBasicsInstalled('/usr/bin/python3')).toBe(false)
533+
})
534+
535+
it('returns false when spawn rejects (line 54)', async () => {
536+
mockSpawn.mockRejectedValueOnce(new Error('python missing'))
537+
expect(await isSocketBasicsInstalled('/usr/bin/python3')).toBe(false)
538+
})
539+
})

0 commit comments

Comments
 (0)