forked from Vero-protocol/vero-core-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusePerformanceStats.test.ts
More file actions
55 lines (48 loc) · 2.06 KB
/
Copy pathusePerformanceStats.test.ts
File metadata and controls
55 lines (48 loc) · 2.06 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { usePerformanceStats } from "./usePerformanceStats";
describe("usePerformanceStats", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it("starts running by default", () => {
const { result } = renderHook(() => usePerformanceStats(1000));
expect(result.current.running).toBe(true);
});
it("toggle pauses and then resumes", () => {
const { result } = renderHook(() => usePerformanceStats(1000));
act(() => result.current.toggle());
expect(result.current.running).toBe(false);
act(() => result.current.toggle());
expect(result.current.running).toBe(true);
});
it("accumulates samples as the timer advances", () => {
const { result } = renderHook(() => usePerformanceStats(1000));
act(() => vi.advanceTimersByTime(3000));
expect(result.current.samples.length).toBeGreaterThanOrEqual(2);
});
it("does not accumulate samples while paused", () => {
const { result } = renderHook(() => usePerformanceStats(1000));
act(() => result.current.toggle());
const before = result.current.samples.length;
act(() => vi.advanceTimersByTime(3000));
expect(result.current.samples.length).toBe(before);
});
it("restart clears accumulated samples and counters", () => {
const { result } = renderHook(() => usePerformanceStats(1000));
act(() => vi.advanceTimersByTime(3000));
expect(result.current.samples.length).toBeGreaterThan(0);
act(() => result.current.restart());
expect(result.current.samples).toHaveLength(0);
});
it("computed aggregates are non-negative after ticks", () => {
const { result } = renderHook(() => usePerformanceStats(1000));
act(() => vi.advanceTimersByTime(2000));
expect(result.current.peakTps).toBeGreaterThanOrEqual(0);
expect(result.current.avgTps).toBeGreaterThanOrEqual(0);
expect(result.current.latestMaxFee).toBeGreaterThanOrEqual(result.current.latestBaseFee);
});
});