-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartContainer.perf.test.jsx
More file actions
38 lines (32 loc) · 1.33 KB
/
ChartContainer.perf.test.jsx
File metadata and controls
38 lines (32 loc) · 1.33 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
import { describe, expect, test } from 'vitest';
import { performance } from 'node:perf_hooks';
import { computeActiveElementsForStep } from './ChartContainer.jsx';
const createMockChart = (datasetCount = 50, pointsPerDataset = 2000) => {
const datasets = Array.from({ length: datasetCount }, (_, datasetIndex) => ({
label: `dataset-${datasetIndex}`,
data: Array.from({ length: pointsPerDataset }, (_, pointIndex) => ({
x: pointIndex,
y: datasetIndex + pointIndex
}))
}));
return {
data: { datasets },
tooltip: { setActiveElements: () => {} },
setActiveElements: () => {},
scales: { x: { getPixelForValue: () => 0 } },
draw: () => {}
};
};
describe('computeActiveElementsForStep performance', () => {
test('processes large datasets within an acceptable time budget', () => {
const chart = createMockChart();
const targetStep = 1500; // exists in every dataset
const start = performance.now();
const activeElements = computeActiveElementsForStep(chart, targetStep);
const durationMs = performance.now() - start;
// Each dataset should yield one active element for the target step
expect(activeElements.length).toBe(chart.data.datasets.length);
// Guardrail to catch regressions; high enough to avoid flakiness in CI
expect(durationMs).toBeLessThan(50);
});
});