The merge landed main's `minimize-to-tray` and `hud-modifier-types` modules next to ours, leaving two `perfectionist/sort-imports` errors — the only blocking failures in the `JS & TS checks` job (`apps/desktop :: check:lint`): electron/main.ts:321 ./minimize-to-tray before ./native-auth-decisions src/global.d.ts:6 ../electron/hud-modifier-types before ../electron/machine-profile Resolved with the workspace's own `npm run fix` (eslint --fix + prettier), which also pads the `padding-line-between-statements` warnings it can. Lint is 0 errors after.
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { EventEmitter } from 'node:events'
|
|
|
|
import { test, vi } from 'vitest'
|
|
|
|
import { waitForBackendExit } from './backend-child'
|
|
|
|
test('backend exit escalation rejects within its bound when no exit or close arrives', async (): Promise<void> => {
|
|
vi.useFakeTimers()
|
|
|
|
try {
|
|
const child = Object.assign(new EventEmitter(), { exitCode: null, signalCode: null, kill: vi.fn() })
|
|
|
|
const waiting = assert.rejects(
|
|
waitForBackendExit(child, { forceKillProcessTree: (): void => {} }, 20),
|
|
/did not exit/
|
|
)
|
|
|
|
await Promise.all([waiting, vi.advanceTimersByTimeAsync(1020)])
|
|
assert.equal(child.exitCode, null)
|
|
assert.equal(child.signalCode, null)
|
|
assert.equal(child.kill.mock.calls.length, 1)
|
|
assert.equal(child.kill.mock.calls[0][0], 'SIGKILL')
|
|
assert.equal(child.listenerCount('exit'), 0)
|
|
assert.equal(vi.getTimerCount(), 0)
|
|
} finally {
|
|
vi.useRealTimers()
|
|
}
|
|
})
|
|
|
|
test('a failed escalation is not evidence that the child exited', async () => {
|
|
vi.useFakeTimers()
|
|
|
|
try {
|
|
const child = Object.assign(new EventEmitter(), {
|
|
exitCode: null,
|
|
signalCode: null,
|
|
kill: () => {
|
|
throw new Error('signal denied')
|
|
}
|
|
})
|
|
|
|
const outcome = waitForBackendExit(child, { forceKillProcessTree: () => {} }, 20).then(
|
|
() => null,
|
|
error => error
|
|
)
|
|
|
|
await vi.advanceTimersByTimeAsync(1020)
|
|
assert.match(String(await outcome), /did not exit/)
|
|
assert.equal(child.listenerCount('exit'), 0)
|
|
assert.equal(vi.getTimerCount(), 0)
|
|
} finally {
|
|
vi.useRealTimers()
|
|
}
|
|
})
|