fix: improve shutdown and project continuity

This commit is contained in:
lofyer
2026-08-07 18:46:26 +08:00
parent 53d18e2b06
commit 954b42ef55
10 changed files with 245 additions and 34 deletions
+26
View File
@@ -0,0 +1,26 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { waitForCleanup } from './shutdown'
afterEach(() => {
vi.useRealTimers()
})
describe('waitForCleanup', () => {
it('reports completed and failed cleanup as settled', async () => {
await expect(
waitForCleanup(Promise.resolve(), 100)
).resolves.toBe(true)
await expect(
waitForCleanup(Promise.reject(new Error('cleanup failed')), 100)
).resolves.toBe(true)
})
it('stops waiting after the shutdown deadline', async () => {
vi.useFakeTimers()
const result = waitForCleanup(new Promise(() => {}), 100)
await vi.advanceTimersByTimeAsync(100)
await expect(result).resolves.toBe(false)
})
})