Skip to content

Commit 42942e3

Browse files
committed
test(coverage): cover getWorkspaceGlobs + globWorkspace
Adds tests for two previously-untested public functions in fs/glob.mts: getWorkspaceGlobs: - PNPM agent reads pnpm-workspace.yaml and returns parsed glob patterns - Missing pnpm-workspace.yaml → empty array - Malformed YAML → empty array (catch branch at lines 53-55) globWorkspace: - Empty workspaceGlobs → early-return [] (line 299-300) glob.mts: 89.32% → 98.05% statements (87.20% → 93.02% branch), function coverage 89.47% → 100%. Remaining gap is the non-PNPM package.json workspaces fallback (line 58, 262).
1 parent 8306969 commit 42942e3

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

packages/cli/test/unit/utils/fs/glob.test.mts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,53 @@ describe('utils/fs/glob', () => {
350350
expect(result).toEqual(['**/node_modules', '**/dist'])
351351
})
352352
})
353+
354+
describe('getWorkspaceGlobs', () => {
355+
it('reads pnpm-workspace.yaml packages list for PNPM agent (lines 49-56)', async () => {
356+
const { safeReadFile } = vi.mocked(await import('@socketsecurity/lib/fs'))
357+
safeReadFile.mockResolvedValueOnce(
358+
'packages:\n - "packages/*"\n - "apps/*"\n',
359+
)
360+
const { getWorkspaceGlobs } = await import(
361+
'../../../../src/utils/fs/glob.mts'
362+
)
363+
const result = await getWorkspaceGlobs('pnpm', '/repo')
364+
// Workspace patterns are converted to glob form ("packages/*" → "packages/*/").
365+
expect(Array.isArray(result)).toBe(true)
366+
expect(result.length).toBeGreaterThan(0)
367+
})
368+
369+
it('returns empty array when pnpm-workspace.yaml is missing', async () => {
370+
const { safeReadFile } = vi.mocked(await import('@socketsecurity/lib/fs'))
371+
safeReadFile.mockResolvedValueOnce(undefined as any)
372+
const { getWorkspaceGlobs } = await import(
373+
'../../../../src/utils/fs/glob.mts'
374+
)
375+
const result = await getWorkspaceGlobs('pnpm', '/repo')
376+
expect(result).toEqual([])
377+
})
378+
379+
it('returns empty array when pnpm-workspace.yaml is malformed', async () => {
380+
const { safeReadFile } = vi.mocked(await import('@socketsecurity/lib/fs'))
381+
safeReadFile.mockResolvedValueOnce('this is not :::valid::: yaml{{{')
382+
const { getWorkspaceGlobs } = await import(
383+
'../../../../src/utils/fs/glob.mts'
384+
)
385+
const result = await getWorkspaceGlobs('pnpm', '/repo')
386+
expect(result).toEqual([])
387+
})
388+
})
389+
390+
describe('globWorkspace', () => {
391+
it('returns empty array when no workspace globs (line 299-300)', async () => {
392+
const { safeReadFile } = vi.mocked(await import('@socketsecurity/lib/fs'))
393+
// pnpm-workspace.yaml missing → empty workspaceGlobs → early-return [].
394+
safeReadFile.mockResolvedValueOnce(undefined as any)
395+
const { globWorkspace } = await import(
396+
'../../../../src/utils/fs/glob.mts'
397+
)
398+
const result = await globWorkspace('pnpm', '/nonexistent/repo')
399+
expect(result).toEqual([])
400+
})
401+
})
353402
})

0 commit comments

Comments
 (0)