This commit is contained in:
Matěj Kubíček
2026-09-02 20:38:45 +02:00
parent 0c524ed6af
commit c7948a788a
46 changed files with 10099 additions and 152 deletions
+21
View File
@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest';
import { ResultCache, hashBlob } from '../src/background/cache';
describe('result cache', () => {
it('evicts the least recently used entry', () => {
const cache = new ResultCache<number>(2);
cache.set('one', 1);
cache.set('two', 2);
expect(cache.get('one')).toBe(1);
cache.set('three', 3);
expect(cache.get('two')).toBeUndefined();
expect(cache.get('one')).toBe(1);
});
it('hashes identical content consistently', async () => {
const first = await hashBlob(new Blob(['same content']));
const second = await hashBlob(new Blob(['same content']));
expect(first).toBe(second);
expect(first).toMatch(/^[a-f0-9]{64}$/);
});
});