From 2ee9744a2437d8b9553b133384668b59ee78c026 Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Wed, 18 Feb 2026 10:23:59 -0800 Subject: [PATCH] fix sbom test error Signed-off-by: Brian DeHamer --- __tests__/unit/sbom.test.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/__tests__/unit/sbom.test.ts b/__tests__/unit/sbom.test.ts index b54291f..1f0e625 100644 --- a/__tests__/unit/sbom.test.ts +++ b/__tests__/unit/sbom.test.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals' import fs from 'fs/promises' import os from 'os' import path from 'path' @@ -17,10 +18,22 @@ describe('parseSBOMFromPath', () => { describe('file handling', () => { it('should throw when file does not exist', async () => { await expect(parseSBOMFromPath('/nonexistent/file.json')).rejects.toThrow( - /ENOENT/ + /SBOM file not found/ ) }) + it('should rethrow non-ENOENT errors', async () => { + const statSpy = jest.spyOn(fs, 'stat').mockRejectedValueOnce( + Object.assign(new Error('Permission denied'), { code: 'EACCES' }) + ) + + await expect(parseSBOMFromPath('/some/file.json')).rejects.toThrow( + /Permission denied/ + ) + + statSpy.mockRestore() + }) + it('should throw when file contains invalid JSON', async () => { const filePath = path.join(tempDir, 'invalid.json') await fs.writeFile(filePath, 'not valid json')