mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 06:36:49 +09:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
// Test setup and configuration
|
|
const { MongoMemoryServer } = require('mongodb-memory-server');
|
|
const mongoose = require('mongoose');
|
|
|
|
let mongod;
|
|
|
|
// Setup before all tests
|
|
beforeAll(async () => {
|
|
// Create an in-memory MongoDB instance
|
|
mongod = await MongoMemoryServer.create();
|
|
const uri = mongod.getUri();
|
|
|
|
// Connect to the in-memory database
|
|
await mongoose.connect(uri, {
|
|
useNewUrlParser: true,
|
|
useUnifiedTopology: true,
|
|
});
|
|
});
|
|
|
|
// Cleanup after each test
|
|
afterEach(async () => {
|
|
// Clear all collections
|
|
const collections = mongoose.connection.collections;
|
|
for (const key in collections) {
|
|
const collection = collections[key];
|
|
await collection.deleteMany({});
|
|
}
|
|
});
|
|
|
|
// Cleanup after all tests
|
|
afterAll(async () => {
|
|
// Disconnect and stop the in-memory MongoDB instance
|
|
await mongoose.connection.dropDatabase();
|
|
await mongoose.connection.close();
|
|
await mongod.stop();
|
|
});
|
|
|
|
// Global test timeout
|
|
jest.setTimeout(30000);
|
|
|
|
// Mock console methods in test environment
|
|
global.console = {
|
|
...console,
|
|
error: jest.fn(),
|
|
warn: jest.fn(),
|
|
log: jest.fn(),
|
|
}; |