test(dev-indices): cover loadManifest error branches + markDeleted no-op

This commit is contained in:
Дмитрий
2026-05-12 11:43:59 +03:00
parent baf51bd2cf
commit 1f834bfac3
3 changed files with 24 additions and 1 deletions
@@ -95,4 +95,27 @@ describe('manifest', () => {
expect(() => readFileSync(path + '.tmp')).toThrow();
rmSync(dir, { recursive: true });
});
it('loadManifest throws on corrupt JSON with actionable message', () => {
const dir = mkdtempSync(join(tmpdir(), 'dx-'));
const path = join(dir, 'm.json');
writeFileSync(path, '{not valid json', 'utf8');
expect(() => loadManifest(path)).toThrow(/corrupt JSON/);
rmSync(dir, { recursive: true });
});
it('loadManifest throws on unsupported version', () => {
const dir = mkdtempSync(join(tmpdir(), 'dx-'));
const path = join(dir, 'm.json');
writeFileSync(path, JSON.stringify({ version: 2, lastId: 0, entries: {}, deleted: {} }), 'utf8');
expect(() => loadManifest(path)).toThrow(/version 2 unsupported/);
rmSync(dir, { recursive: true });
});
it('markDeleted is a no-op for unknown ids (does not throw)', () => {
const m = createEmpty();
expect(() => markDeleted(m, 9999)).not.toThrow();
expect(m.deleted['9999']).toBeUndefined();
expect(m.lastId).toBe(0);
});
});
+1
View File
@@ -56,6 +56,7 @@ export function addEntry(manifest: Manifest, entry: ManifestEntry): number {
export function markDeleted(manifest: Manifest, id: number): void {
const key = String(id);
const entry = manifest.entries[key];
// no-op if id was never added or already deleted — defensive, callers should not rely on this
if (!entry) return;
manifest.deleted[key] = {
lastSignature: entry.signature,
@@ -3,7 +3,6 @@ import { defineConfig } from 'vitest/config';
// Vitest config for dev-indices Vite plugin (pure Node, no jsdom)
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['__tests__/**/*.{test,spec}.ts'],
},