-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathauto-refresh-controller.test.ts
More file actions
31 lines (26 loc) · 1.23 KB
/
auto-refresh-controller.test.ts
File metadata and controls
31 lines (26 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { describe, it, expect } from 'vitest';
import { createAutoRefreshController } from '../src/core/auto-refresh.js';
describe('AutoRefreshController', () => {
it('runs immediately when not indexing', () => {
const controller = createAutoRefreshController();
expect(controller.onFileChange(false)).toBe(true);
});
it('queues when indexing and runs after ready', () => {
const controller = createAutoRefreshController();
expect(controller.onFileChange(true)).toBe(false);
expect(controller.consumeQueuedRefresh('indexing')).toBe(false);
expect(controller.consumeQueuedRefresh('ready')).toBe(true);
});
it('does not run queued refresh if indexing failed', () => {
const controller = createAutoRefreshController();
expect(controller.onFileChange(true)).toBe(false);
expect(controller.consumeQueuedRefresh('error')).toBe(false);
});
it('coalesces multiple changes into one queued refresh', () => {
const controller = createAutoRefreshController();
expect(controller.onFileChange(true)).toBe(false);
expect(controller.onFileChange(true)).toBe(false);
expect(controller.consumeQueuedRefresh('ready')).toBe(true);
expect(controller.consumeQueuedRefresh('ready')).toBe(false);
});
});