⚡ Zero-dependency plcbundle library exclusively for Bun
1import { describe, test, expect } from 'bun:test';
2import { PLCBundle } from '../src/plcbundle';
3
4describe('Error Handling', () => {
5 test('handles missing index file gracefully', async () => {
6 const bundle = new PLCBundle('/nonexistent/path');
7
8 try {
9 await bundle.loadIndex();
10 expect(true).toBe(false); // Should throw
11 } catch (error) {
12 expect(error).toBeDefined();
13 }
14 });
15
16 test('handles invalid bundle numbers', async () => {
17 const bundle = new PLCBundle('./test-data');
18
19 // Test with negative number - padStart will create "0000-1"
20 const path = bundle.getBundlePath(-1);
21 expect(path).toContain('0000-1.jsonl.zst');
22
23 // Test with zero
24 const path0 = bundle.getBundlePath(0);
25 expect(path0).toContain('000000.jsonl.zst');
26
27 // Test with large number
28 const pathLarge = bundle.getBundlePath(999999);
29 expect(pathLarge).toContain('999999.jsonl.zst');
30 });
31
32 test('handles malformed operations', () => {
33 const bundle = new PLCBundle();
34
35 try {
36 bundle.parseOperations('invalid json\n{bad');
37 expect(true).toBe(false); // Should throw
38 } catch (error) {
39 expect(error).toBeDefined();
40 }
41 });
42});