also looking at this
test: measure coverage, and call the three files nothing called
#1442
4 files
+210
-0
| @@ -0,0 +1,67 @@ | ||
| 1 | import { describe, expect, it } from 'bun:test' | |
| 2 | import { isPantryLockFile, parsePantryLockFile } from '../src/utils/pantry-parser' | |
| 3 | ||
| 4 | /** | |
| 5 | * 0% function coverage before this file: the parser is wired into the | |
| 6 | * package scanner and was never once called by a test, so a regression here | |
| 7 | * would surface as pantry.lock silently vanishing from the dashboard. | |
| 8 | */ | |
| 9 | describe('pantry-parser', () => { | |
| 10 | describe('isPantryLockFile', () => { | |
| 11 | it('success case - matches the lock file wherever it lives', () => { | |
| 12 | expect(isPantryLockFile('pantry.lock')).toBe(true) | |
| 13 | expect(isPantryLockFile('packages/app/pantry.lock')).toBe(true) | |
| 14 | }) | |
| 15 | ||
| 16 | it('failure case - near-misses are not lock files', () => { | |
| 17 | expect(isPantryLockFile('pantry.lock.bak')).toBe(false) | |
| 18 | expect(isPantryLockFile('pantry.yaml')).toBe(false) | |
| 19 | expect(isPantryLockFile('bun.lock')).toBe(false) | |
| 20 | }) | |
| 21 | }) | |
| 22 | ||
| 23 | describe('parsePantryLockFile', () => { | |
| 24 | const lock = { | |
| 25 | version: '1', | |
| 26 | packages: { | |
| 27 | 'bun.com': { name: 'bun.com', version: '1.2.19', resolved: 'https://example.com/bun' }, | |
| 28 | 'node': { name: 'node', version: '22.3.0', resolved: 'https://example.com/node' }, | |
| 29 | }, | |
| 30 | } | |
| 31 | ||
| 32 | it('success case - extracts every resolved package', async () => { | |
| 33 | const parsed = await parsePantryLockFile('pantry.lock', JSON.stringify(lock)) | |
| 34 | ||
| 35 | expect(parsed?.type).toBe('pantry.lock') | |
| 36 | expect(parsed?.dependencies).toEqual([ | |
| 37 | { name: 'bun.com', currentVersion: '1.2.19', type: 'dependencies', file: 'pantry.lock' }, | |
| 38 | { name: 'node', currentVersion: '22.3.0', type: 'dependencies', file: 'pantry.lock' }, | |
| 39 | ]) | |
| 40 | }) | |
| 41 | ||
| 42 | it('edge case - entries missing a name or version are skipped', async () => { | |
| 43 | const partial = { | |
| 44 | version: '1', | |
| 45 | packages: { | |
| 46 | ok: { name: 'ok', version: '1.0.0', resolved: '' }, | |
| 47 | nameless: { version: '2.0.0', resolved: '' }, | |
| 48 | versionless: { name: 'versionless', resolved: '' }, | |
| 49 | }, | |
| 50 | } | |
| 51 | ||
| 52 | const parsed = await parsePantryLockFile('pantry.lock', JSON.stringify(partial)) | |
| 53 | ||
| 54 | expect(parsed?.dependencies.map(dep => dep.name)).toEqual(['ok']) | |
| 55 | }) | |
| 56 | ||
| 57 | it('edge case - a lock without packages parses to no dependencies', async () => { | |
| 58 | const parsed = await parsePantryLockFile('pantry.lock', JSON.stringify({ version: '1' })) | |
| 59 | ||
| 60 | expect(parsed?.dependencies).toEqual([]) | |
| 61 | }) | |
| 62 | ||
| 63 | it('failure case - malformed JSON returns null rather than throwing', async () => { | |
| 64 | expect(await parsePantryLockFile('pantry.lock', 'not json {')).toBeNull() | |
| 65 | }) | |
| 66 | }) | |
| 67 | }) | |