openreader/tests/global-teardown.ts
Richard R 4a5f3060f2 refactor(documents): migrate from IndexedDB to server-backed storage with caching
- Replace client-side IndexedDB with server-first document storage
- Add document caching layer for offline capability and performance
- Implement document transfer during anonymous-to-authenticated account linking
- Add database indexes for improved query performance
- Update document contexts to use new caching system
- Refactor document upload and deletion APIs
- Add audiobook pruning for missing files
- Improve test isolation with namespace support
- Add unit tests for document cache and transfer functions
2026-02-08 11:15:57 -07:00

29 lines
910 B
TypeScript

import fs from 'fs/promises';
import path from 'path';
async function listWorkerNamespaces(documentsRoot: string): Promise<string[]> {
let entries: Array<{ name: string; isDirectory: () => boolean }> = [];
try {
entries = await fs.readdir(documentsRoot, { withFileTypes: true });
} catch {
return [];
}
return entries
.filter((d) => d.isDirectory())
.map((d) => d.name)
.filter((name) => /^(chromium|firefox|webkit)-worker\d+$/.test(name));
}
export default async function globalTeardown(): Promise<void> {
const documentsRoot = path.join(process.cwd(), 'docstore', 'documents_v1');
const namespaces = await listWorkerNamespaces(documentsRoot);
if (!namespaces.length) return;
await Promise.all(
namespaces.map(async (ns) => {
const dir = path.join(documentsRoot, ns);
await fs.rm(dir, { recursive: true, force: true }).catch(() => {});
}),
);
}