feat: Add testing framework and initial test cases for various tools and database operations
This commit is contained in:
29
tests/helpers/database-helper.ts
Normal file
29
tests/helpers/database-helper.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Database test helper - creates isolated database instances for testing
|
||||
*/
|
||||
|
||||
import { database } from "../../src/storage/database.js";
|
||||
import { join } from "path";
|
||||
import { mkdirSync } from "fs";
|
||||
import type { TestContext } from "./test-utils.js";
|
||||
|
||||
/**
|
||||
* Setup test database with isolated data directory
|
||||
*/
|
||||
export function setupTestDatabase(testContext: TestContext): () => void {
|
||||
const testDataDir = join(testContext.tempDir, "data");
|
||||
mkdirSync(testDataDir, { recursive: true });
|
||||
|
||||
// Set environment variable for test data directory
|
||||
const originalDataDir = process.env.MCP_TEST_DATA_DIR;
|
||||
process.env.MCP_TEST_DATA_DIR = testDataDir;
|
||||
|
||||
// Return cleanup function
|
||||
return () => {
|
||||
if (originalDataDir) {
|
||||
process.env.MCP_TEST_DATA_DIR = originalDataDir;
|
||||
} else {
|
||||
delete process.env.MCP_TEST_DATA_DIR;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user