stock-bot/libs/core/shutdown/test/index.test.ts
2025-06-26 16:12:27 -04:00

66 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'bun:test';
import * as shutdownExports from '../src';
import { Shutdown } from '../src';
describe('Shutdown Package Exports', () => {
it('should export all main functions', () => {
expect(shutdownExports.onShutdown).toBeDefined();
expect(shutdownExports.onShutdownHigh).toBeDefined();
expect(shutdownExports.onShutdownMedium).toBeDefined();
expect(shutdownExports.onShutdownLow).toBeDefined();
expect(shutdownExports.setShutdownTimeout).toBeDefined();
expect(shutdownExports.isShuttingDown).toBeDefined();
expect(shutdownExports.isShutdownSignalReceived).toBeDefined();
expect(shutdownExports.getShutdownCallbackCount).toBeDefined();
expect(shutdownExports.initiateShutdown).toBeDefined();
expect(shutdownExports.shutdownAndExit).toBeDefined();
expect(shutdownExports.resetShutdown).toBeDefined();
});
it('should export Shutdown class', () => {
expect(shutdownExports.Shutdown).toBeDefined();
expect(shutdownExports.Shutdown).toBe(Shutdown);
});
it('should export correct function types', () => {
expect(typeof shutdownExports.onShutdown).toBe('function');
expect(typeof shutdownExports.onShutdownHigh).toBe('function');
expect(typeof shutdownExports.onShutdownMedium).toBe('function');
expect(typeof shutdownExports.onShutdownLow).toBe('function');
expect(typeof shutdownExports.setShutdownTimeout).toBe('function');
expect(typeof shutdownExports.isShuttingDown).toBe('function');
expect(typeof shutdownExports.isShutdownSignalReceived).toBe('function');
expect(typeof shutdownExports.getShutdownCallbackCount).toBe('function');
expect(typeof shutdownExports.initiateShutdown).toBe('function');
expect(typeof shutdownExports.shutdownAndExit).toBe('function');
expect(typeof shutdownExports.resetShutdown).toBe('function');
});
it('should export type definitions', () => {
// Type tests - these compile-time checks ensure types are exported
type TestShutdownCallback = shutdownExports.ShutdownCallback;
type TestShutdownOptions = shutdownExports.ShutdownOptions;
type TestShutdownResult = shutdownExports.ShutdownResult;
type TestPrioritizedShutdownCallback = shutdownExports.PrioritizedShutdownCallback;
// Runtime check that types can be used
const testCallback: TestShutdownCallback = async () => {};
const testOptions: TestShutdownOptions = { timeout: 5000, autoRegister: false };
const testResult: TestShutdownResult = {
success: true,
callbacksExecuted: 1,
callbacksFailed: 0,
duration: 100,
};
const testPrioritized: TestPrioritizedShutdownCallback = {
callback: testCallback,
priority: 50,
name: 'test',
};
expect(testCallback).toBeDefined();
expect(testOptions).toBeDefined();
expect(testResult).toBeDefined();
expect(testPrioritized).toBeDefined();
});
});