|
| 1 | +import { Volume } from '../volume'; |
| 2 | +import StatFs from '../StatFs'; |
| 3 | + |
| 4 | +describe('statfs API', () => { |
| 5 | + describe('.statfsSync(path)', () => { |
| 6 | + const vol = new Volume(); |
| 7 | + vol.mkdirSync('/test'); |
| 8 | + vol.writeFileSync('/test/file.txt', 'hello world'); |
| 9 | + |
| 10 | + it('Returns StatFs instance', () => { |
| 11 | + const statfs = vol.statfsSync('/test'); |
| 12 | + expect(statfs).toBeInstanceOf(StatFs); |
| 13 | + }); |
| 14 | + |
| 15 | + it('Returns filesystem statistics', () => { |
| 16 | + const statfs = vol.statfsSync('/'); |
| 17 | + expect(typeof statfs.type).toBe('number'); |
| 18 | + expect(typeof statfs.bsize).toBe('number'); |
| 19 | + expect(typeof statfs.blocks).toBe('number'); |
| 20 | + expect(typeof statfs.bfree).toBe('number'); |
| 21 | + expect(typeof statfs.bavail).toBe('number'); |
| 22 | + expect(typeof statfs.files).toBe('number'); |
| 23 | + expect(typeof statfs.ffree).toBe('number'); |
| 24 | + |
| 25 | + expect(statfs.bsize).toBeGreaterThan(0); |
| 26 | + expect(statfs.blocks).toBeGreaterThan(0); |
| 27 | + expect(statfs.files).toBeGreaterThan(0); |
| 28 | + }); |
| 29 | + |
| 30 | + it('Works with bigint option', () => { |
| 31 | + const statfs = vol.statfsSync('/', { bigint: true }); |
| 32 | + expect(typeof statfs.type).toBe('bigint'); |
| 33 | + expect(typeof statfs.bsize).toBe('bigint'); |
| 34 | + expect(typeof statfs.blocks).toBe('bigint'); |
| 35 | + expect(typeof statfs.bfree).toBe('bigint'); |
| 36 | + expect(typeof statfs.bavail).toBe('bigint'); |
| 37 | + expect(typeof statfs.files).toBe('bigint'); |
| 38 | + expect(typeof statfs.ffree).toBe('bigint'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('Throws when path does not exist', () => { |
| 42 | + expect(() => vol.statfsSync('/nonexistent')).toThrow(); |
| 43 | + }); |
| 44 | + |
| 45 | + it('Works with different paths in same filesystem', () => { |
| 46 | + const statfs1 = vol.statfsSync('/'); |
| 47 | + const statfs2 = vol.statfsSync('/test'); |
| 48 | + |
| 49 | + // Should return same filesystem stats for any path |
| 50 | + expect(statfs1.type).toBe(statfs2.type); |
| 51 | + expect(statfs1.bsize).toBe(statfs2.bsize); |
| 52 | + expect(statfs1.blocks).toBe(statfs2.blocks); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('.statfs(path, callback)', () => { |
| 57 | + const vol = new Volume(); |
| 58 | + vol.mkdirSync('/test'); |
| 59 | + vol.writeFileSync('/test/file.txt', 'hello world'); |
| 60 | + |
| 61 | + it('Calls callback with StatFs instance', done => { |
| 62 | + vol.statfs('/test', (err, statfs) => { |
| 63 | + expect(err).toBeNull(); |
| 64 | + expect(statfs).toBeInstanceOf(StatFs); |
| 65 | + expect(statfs).toBeDefined(); |
| 66 | + expect(typeof statfs!.type).toBe('number'); |
| 67 | + expect(statfs!.bsize).toBeGreaterThan(0); |
| 68 | + done(); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + it('Works with bigint option', done => { |
| 73 | + vol.statfs('/', { bigint: true }, (err, statfs) => { |
| 74 | + expect(err).toBeNull(); |
| 75 | + expect(statfs).toBeDefined(); |
| 76 | + expect(typeof statfs!.type).toBe('bigint'); |
| 77 | + expect(typeof statfs!.bsize).toBe('bigint'); |
| 78 | + done(); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + it('Calls callback with error when path does not exist', done => { |
| 83 | + vol.statfs('/nonexistent', (err, statfs) => { |
| 84 | + expect(err).toBeTruthy(); |
| 85 | + expect(err).toBeDefined(); |
| 86 | + expect(err!.code).toBe('ENOENT'); |
| 87 | + expect(statfs).toBeUndefined(); |
| 88 | + done(); |
| 89 | + }); |
| 90 | + }); |
| 91 | + }); |
| 92 | +}); |
0 commit comments