@@ -1,3 +1,4 @@
|
|||||||
|
import { jest } from '@jest/globals'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
@@ -17,10 +18,22 @@ describe('parseSBOMFromPath', () => {
|
|||||||
describe('file handling', () => {
|
describe('file handling', () => {
|
||||||
it('should throw when file does not exist', async () => {
|
it('should throw when file does not exist', async () => {
|
||||||
await expect(parseSBOMFromPath('/nonexistent/file.json')).rejects.toThrow(
|
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 () => {
|
it('should throw when file contains invalid JSON', async () => {
|
||||||
const filePath = path.join(tempDir, 'invalid.json')
|
const filePath = path.join(tempDir, 'invalid.json')
|
||||||
await fs.writeFile(filePath, 'not valid json')
|
await fs.writeFile(filePath, 'not valid json')
|
||||||
|
|||||||
Reference in New Issue
Block a user