fixed format issues

This commit is contained in:
Boki 2025-06-26 16:12:27 -04:00
parent a700818a06
commit 08f713d98b
55 changed files with 5680 additions and 5533 deletions

View file

@ -10,8 +10,8 @@ import {
onShutdownMedium,
resetShutdown,
setShutdownTimeout,
shutdownAndExit,
Shutdown,
shutdownAndExit,
} from '../src';
import type { ShutdownOptions, ShutdownResult } from '../src/types';
@ -104,7 +104,9 @@ describe('Shutdown Comprehensive Tests', () => {
it('should handle negative timeout values', () => {
// Should throw for negative values
expect(() => setShutdownTimeout(-1000)).toThrow('Shutdown timeout must be a positive number');
expect(() => setShutdownTimeout(-1000)).toThrow(
'Shutdown timeout must be a positive number'
);
});
it('should handle zero timeout', () => {
@ -415,7 +417,7 @@ describe('Shutdown Comprehensive Tests', () => {
onShutdown(callback);
await expect(shutdownAndExit('SIGTERM', 1)).rejects.toThrow('Process exit called');
expect(callback).toHaveBeenCalledTimes(1);
expect(exitMock).toHaveBeenCalledWith(1);
} finally {
@ -446,7 +448,7 @@ describe('Shutdown Comprehensive Tests', () => {
onShutdown(callback);
const result = await initiateShutdown('CUSTOM_SIGNAL');
expect(result.success).toBe(true);
expect(callback).toHaveBeenCalled();
});
@ -454,7 +456,7 @@ describe('Shutdown Comprehensive Tests', () => {
it('should handle shutdown from getInstance without options', () => {
const instance = Shutdown.getInstance();
expect(instance).toBeInstanceOf(Shutdown);
// Call again to test singleton
const instance2 = Shutdown.getInstance();
expect(instance2).toBe(instance);
@ -464,11 +466,11 @@ describe('Shutdown Comprehensive Tests', () => {
// Start fresh
resetShutdown();
expect(getShutdownCallbackCount()).toBe(0);
// Add callback - this creates global instance
onShutdown(async () => {});
expect(getShutdownCallbackCount()).toBe(1);
// Reset and verify
resetShutdown();
expect(getShutdownCallbackCount()).toBe(0);
@ -484,7 +486,7 @@ describe('Shutdown Comprehensive Tests', () => {
onShutdown(undefinedRejectCallback, 'undefined-reject');
const result = await initiateShutdown();
expect(result.callbacksFailed).toBe(1);
expect(result.success).toBe(false);
});
@ -497,7 +499,7 @@ describe('Shutdown Comprehensive Tests', () => {
onShutdown(nullRejectCallback, 'null-reject');
const result = await initiateShutdown();
expect(result.callbacksFailed).toBe(1);
expect(result.success).toBe(false);
});
@ -506,7 +508,7 @@ describe('Shutdown Comprehensive Tests', () => {
const syncCallback = mock(() => {
// Synchronous - returns void
});
const asyncCallback = mock(async () => {
await new Promise(resolve => setTimeout(resolve, 10));
});
@ -515,7 +517,7 @@ describe('Shutdown Comprehensive Tests', () => {
onShutdown(asyncCallback);
const result = await initiateShutdown();
expect(result.callbacksExecuted).toBe(2);
expect(syncCallback).toHaveBeenCalled();
expect(asyncCallback).toHaveBeenCalled();
@ -525,27 +527,27 @@ describe('Shutdown Comprehensive Tests', () => {
describe('Shutdown Method Variants', () => {
it('should handle direct priority parameter in onShutdown', () => {
const callback = mock(async () => {});
// Test with name and priority swapped (legacy support)
onShutdown(callback, 75, 'custom-name');
expect(getShutdownCallbackCount()).toBe(1);
});
it('should handle callback without any parameters', () => {
const callback = mock(async () => {});
onShutdown(callback);
expect(getShutdownCallbackCount()).toBe(1);
});
it('should validate setTimeout input', () => {
const shutdown = new Shutdown();
// Valid timeout
expect(() => shutdown.setTimeout(5000)).not.toThrow();
// Invalid timeouts should throw
expect(() => shutdown.setTimeout(-1)).toThrow();
expect(() => shutdown.setTimeout(0)).toThrow();