22 lines
723 B
TypeScript
22 lines
723 B
TypeScript
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}$/);
|
|
});
|
|
});
|