43 lines
No EOL
1.2 KiB
JavaScript
43 lines
No EOL
1.2 KiB
JavaScript
// Jest teardown file - runs after all tests complete
|
|
// This helps prevent async operations from continuing after Jest environment teardown
|
|
|
|
// Global teardown to ensure clean test environment shutdown
|
|
module.exports = async () => {
|
|
// Clear all timers first
|
|
if (typeof global.clearAllTimers === 'function') {
|
|
global.clearAllTimers();
|
|
}
|
|
|
|
// Clear any pending setImmediate calls
|
|
if (global.pendingImmediates) {
|
|
global.pendingImmediates.forEach(id => clearImmediate(id));
|
|
global.pendingImmediates.clear();
|
|
}
|
|
|
|
// Force close any remaining handles
|
|
if (process._getActiveHandles) {
|
|
const handles = process._getActiveHandles();
|
|
handles.forEach(handle => {
|
|
if (handle && typeof handle.close === 'function') {
|
|
try {
|
|
handle.close();
|
|
} catch (e) {
|
|
// Ignore errors during forced cleanup
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// Force garbage collection if available
|
|
if (global.gc) {
|
|
global.gc();
|
|
}
|
|
|
|
// Add a small delay to allow any pending async operations to complete
|
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
|
|
// Clear any remaining console overrides
|
|
if (global.originalConsole) {
|
|
Object.assign(console, global.originalConsole);
|
|
}
|
|
};
|