mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
77 lines
1.7 KiB
TypeScript
77 lines
1.7 KiB
TypeScript
// Global test setup
|
|
import 'reflect-metadata';
|
|
|
|
// Mock environment variables for testing
|
|
Object.assign(process.env, {
|
|
NODE_ENV: 'test',
|
|
JWT_SECRET: 'test-jwt-secret-key',
|
|
DATABASE_URL: 'sqlite::memory:',
|
|
});
|
|
|
|
// Global test utilities
|
|
declare global {
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
namespace jest {
|
|
interface Matchers<R> {
|
|
toBeValidDate(): R;
|
|
toBeValidUUID(): R;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Custom matchers
|
|
expect.extend({
|
|
toBeValidDate(received: any) {
|
|
const pass = received instanceof Date && !isNaN(received.getTime());
|
|
if (pass) {
|
|
return {
|
|
message: () => `expected ${received} not to be a valid date`,
|
|
pass: true,
|
|
};
|
|
} else {
|
|
return {
|
|
message: () => `expected ${received} to be a valid date`,
|
|
pass: false,
|
|
};
|
|
}
|
|
},
|
|
|
|
toBeValidUUID(received: any) {
|
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
const pass = typeof received === 'string' && uuidRegex.test(received);
|
|
if (pass) {
|
|
return {
|
|
message: () => `expected ${received} not to be a valid UUID`,
|
|
pass: true,
|
|
};
|
|
} else {
|
|
return {
|
|
message: () => `expected ${received} to be a valid UUID`,
|
|
pass: false,
|
|
};
|
|
}
|
|
},
|
|
});
|
|
|
|
// Increase timeout for async operations
|
|
jest.setTimeout(10000);
|
|
|
|
// Mock console methods to reduce noise in tests
|
|
const originalError = console.error;
|
|
const originalWarn = console.warn;
|
|
|
|
beforeAll(() => {
|
|
console.error = jest.fn();
|
|
console.warn = jest.fn();
|
|
});
|
|
|
|
afterAll(() => {
|
|
console.error = originalError;
|
|
console.warn = originalWarn;
|
|
});
|
|
|
|
// Clear all mocks before each test
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|