Skip to content

Commit bfd25be

Browse files
committed
test(cli): add edge case tests for pnpm lockfile parsing
1 parent cafdc46 commit bfd25be

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

packages/cli/test/unit/utils/pnpm/lockfile.test.mts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,59 @@ packages: {}`
347347
const purls = await extractPurlsFromPnpmLockfile(lockfile)
348348
expect(purls).toEqual([])
349349
})
350+
351+
it('handles dependency pointing to non-existent package', async () => {
352+
const lockfile = {
353+
lockfileVersion: 5.4,
354+
packages: {
355+
'/main@1.0.0': {
356+
resolution: { integrity: 'sha512-test' },
357+
dependencies: {
358+
'missing-pkg': '1.0.0',
359+
},
360+
},
361+
// Note: /missing-pkg@1.0.0 is not in packages.
362+
},
363+
}
364+
365+
const purls = await extractPurlsFromPnpmLockfile(lockfile)
366+
// Should include main and handle the missing package gracefully.
367+
// The seen set tracks visited paths but only existing package paths are mapped to purls.
368+
expect(purls).toContain('pkg:npm/main@1.0.0')
369+
expect(purls).toHaveLength(1)
370+
})
371+
372+
it('handles empty dependency reference', async () => {
373+
const lockfile = {
374+
lockfileVersion: 5.4,
375+
packages: {
376+
'/main@1.0.0': {
377+
resolution: { integrity: 'sha512-test' },
378+
dependencies: {
379+
'some-pkg': '',
380+
},
381+
},
382+
},
383+
}
384+
385+
const purls = await extractPurlsFromPnpmLockfile(lockfile)
386+
// Should only include main, empty ref should be skipped.
387+
expect(purls).toHaveLength(1)
388+
expect(purls).toContain('pkg:npm/main@1.0.0')
389+
})
390+
})
391+
392+
describe('stripPnpmPeerSuffix edge cases', () => {
393+
it('handles empty string input', () => {
394+
expect(stripPnpmPeerSuffix('')).toBe('')
395+
})
396+
397+
it('handles null input', () => {
398+
expect(stripPnpmPeerSuffix(null as any)).toBe(null)
399+
})
400+
401+
it('handles undefined input', () => {
402+
expect(stripPnpmPeerSuffix(undefined as any)).toBe(undefined)
403+
})
350404
})
351405
})

0 commit comments

Comments
 (0)