test(dev-indices): cover loadManifest error branches + markDeleted no-op
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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'],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user