Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
61
vendor/ruvector/npm/packages/ruvbot/tests/setup.ts
vendored
Normal file
61
vendor/ruvector/npm/packages/ruvbot/tests/setup.ts
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Test Setup Configuration
|
||||
*
|
||||
* Global setup for all RuvBot tests
|
||||
*/
|
||||
|
||||
import { beforeAll, afterAll, beforeEach, afterEach, vi } from 'vitest';
|
||||
|
||||
// Global test timeout
|
||||
vi.setConfig({ testTimeout: 30000 });
|
||||
|
||||
// Environment setup
|
||||
beforeAll(async () => {
|
||||
// Set test environment variables
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.RUVBOT_TEST_MODE = 'true';
|
||||
process.env.RUVBOT_LOG_LEVEL = 'error';
|
||||
process.env.DATABASE_URL = 'postgresql://test:test@localhost:5432/ruvbot_test';
|
||||
process.env.SLACK_BOT_TOKEN = 'xoxb-test-token';
|
||||
process.env.SLACK_SIGNING_SECRET = 'test-signing-secret';
|
||||
|
||||
// Suppress console output during tests unless DEBUG is set
|
||||
if (!process.env.DEBUG) {
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
vi.spyOn(console, 'info').mockImplementation(() => {});
|
||||
vi.spyOn(console, 'debug').mockImplementation(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
// Cleanup any global resources
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset any per-test state
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Clean up after each test
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
// Global error handler for unhandled rejections in tests
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('Unhandled Rejection in test:', reason);
|
||||
});
|
||||
|
||||
// Export test utilities
|
||||
export const waitFor = async (condition: () => boolean | Promise<boolean>, timeout = 5000): Promise<void> => {
|
||||
const start = Date.now();
|
||||
while (Date.now() - start < timeout) {
|
||||
if (await condition()) return;
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
}
|
||||
throw new Error(`waitFor timeout after ${timeout}ms`);
|
||||
};
|
||||
|
||||
export const delay = (ms: number): Promise<void> =>
|
||||
new Promise(resolve => setTimeout(resolve, ms));
|
||||
Reference in New Issue
Block a user