refactor: item 29 cleanup

F16 F17 F18 F19 F20 F21: import polling backs off and pauses in a hidden tab, one date format module, fake timers in the import tests, error codes instead of raw messages, one safe storage wrapper, dead code.
This commit is contained in:
lobo committed 2026-09-30 15:00:47 +02:00
1 parent aa5832225d
commit 89d0b29698
31 files changed
+238 -81

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
// @vitest-environment jsdom
import {afterEach, describe, expect, it, vi} from 'vitest';
import {storage} from './storage.js';
afterEach(() => {
vi.restoreAllMocks();
localStorage.clear();
});
const blockStorage = () => ['getItem', 'setItem', 'removeItem'].forEach((method) =>
vi.spyOn(Storage.prototype, method).mockImplementation(() => {
throw new DOMException('blocked', 'SecurityError');
}));
describe('storage', () => {
it('reads, writes and removes a value', () => {
storage.set('key', 'value');
expect(storage.get('key')).toBe('value');
storage.remove('key');
expect(storage.get('key')).toBeNull();
});
it('does not throw when localStorage throws, and reads null', () => {
blockStorage();
expect(() => storage.set('key', 'value')).not.toThrow();
expect(() => storage.remove('key')).not.toThrow();
expect(storage.get('key')).toBeNull();
});
});