Files
flynn/src/daemon/lifecycle.test.ts
T
William Valentin 70c3960527 feat: add daemon skeleton with lifecycle management
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 20:56:45 -08:00

40 lines
999 B
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { Lifecycle } from './lifecycle.js';
describe('Lifecycle', () => {
it('registers and calls shutdown handlers in reverse order', async () => {
const lifecycle = new Lifecycle();
const calls: number[] = [];
lifecycle.onShutdown(async () => { calls.push(1); });
lifecycle.onShutdown(async () => { calls.push(2); });
lifecycle.onShutdown(async () => { calls.push(3); });
await lifecycle.shutdown();
expect(calls).toEqual([3, 2, 1]);
});
it('only shuts down once', async () => {
const lifecycle = new Lifecycle();
let count = 0;
lifecycle.onShutdown(async () => { count++; });
await lifecycle.shutdown();
await lifecycle.shutdown();
expect(count).toBe(1);
});
it('reports running state', async () => {
const lifecycle = new Lifecycle();
expect(lifecycle.isRunning).toBe(true);
await lifecycle.shutdown();
expect(lifecycle.isRunning).toBe(false);
});
});