You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			19 lines
		
	
	
		
			677 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			19 lines
		
	
	
		
			677 B
		
	
	
	
		
			TypeScript
		
	
| import { mkdirSync, rmSync } from 'fs';
 | |
| import { join, resolve } from 'path';
 | |
| import Database from 'bun:sqlite';
 | |
| import { initializeDatabase } from '../../../src/db';
 | |
| 
 | |
| export function createTempDb(): { path: string; db: any; cleanup: () => void } {
 | |
|   const dir = join('tmp', 'web-tests');
 | |
|   try { mkdirSync(dir, { recursive: true }); } catch {}
 | |
|   const path = join(dir, `db-${Date.now()}-${Math.random().toString(16).slice(2)}.sqlite`);
 | |
|   const absPath = resolve(path);
 | |
|   const db = new Database(absPath);
 | |
|   initializeDatabase(db);
 | |
|   const cleanup = () => {
 | |
|     try { db.close(); } catch {}
 | |
|     try { rmSync(absPath); } catch {}
 | |
|   };
 | |
|   return { path: absPath, db, cleanup };
 | |
| }
 |