test(tui): make elapsed refresh deterministic
This commit is contained in:
@@ -663,13 +663,24 @@ describe('pi-tui chat lifecycle and transcript', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('refreshes the running status elapsed time on its own timer', async () => {
|
it('refreshes the running status elapsed time on its own timer', async () => {
|
||||||
const result = await setup({ status: 'running' })
|
let now = 0
|
||||||
result.terminal.output = ''
|
const intervals = vi.spyOn(globalThis, 'setInterval')
|
||||||
// The loader repaints "0s" until the controller's own interval fires; a
|
let result: Awaited<ReturnType<typeof setup>> | undefined
|
||||||
// non-zero elapsed proves the refresh, not just the loader's animation.
|
try {
|
||||||
await new Promise(resolve => setTimeout(resolve, 1_300))
|
result = await setup({ status: 'running', now: () => now })
|
||||||
expect(result.terminal.output).toMatch(/Waiting for the first token [1-9]s/)
|
const refresh = intervals.mock.calls.find(([, interval]) => interval === 1_000)?.[0]
|
||||||
await dispose(result)
|
if (typeof refresh !== 'function') throw new Error('TUI did not register its elapsed-status refresh interval')
|
||||||
|
result.terminal.output = ''
|
||||||
|
// The loader repaints "0s" until the controller's own interval fires; a
|
||||||
|
// non-zero elapsed proves the refresh, not just the loader's animation.
|
||||||
|
now = 1_000
|
||||||
|
refresh()
|
||||||
|
await tick()
|
||||||
|
expect(result.terminal.output).toContain('Waiting for the first token 1s')
|
||||||
|
} finally {
|
||||||
|
if (result !== undefined) await dispose(result)
|
||||||
|
intervals.mockRestore()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows minutes and seconds once a step passes a minute', async () => {
|
it('shows minutes and seconds once a step passes a minute', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user