-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbuildMarkdownReport.test.ts
More file actions
189 lines (174 loc) · 7.64 KB
/
Copy pathbuildMarkdownReport.test.ts
File metadata and controls
189 lines (174 loc) · 7.64 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { describe, it, expect } from 'vitest';
import { buildBenchmarkMarkdownReport } from './buildMarkdownReport';
import { compareBenchmarkReports, type BenchmarkComparisonInput } from './compareBenchmarkReports';
import type { BenchmarkReportEntry, MetricDefinition } from './types';
import { makeReport, makeReportFromConfig } from './test-fixtures';
// A single benchmark whose duration/renders are neutral, so the only signal is one metric.
function metricReport(
name: string,
mean: number,
definitions?: Record<string, MetricDefinition>,
): BenchmarkComparisonInput {
const entry: BenchmarkReportEntry = {
iterations: 10,
totalDuration: 100,
renders: [],
metrics: { [name]: { mean, stdDev: 0, outliers: 0 } },
};
return { report: { Bench: entry }, metricDefinitions: definitions };
}
const alarmDefinitions: Record<string, MetricDefinition> = {
clicks: {
kind: 'discrete',
format: { maximumFractionDigits: 0 },
alarm: { direction: 'lowerIsBetter', error: 1 },
},
tti: { kind: 'scalar', alarm: { direction: 'lowerIsBetter', warn: 0.1, error: 0.25 } },
fps: { kind: 'scalar' }, // informational (no alarm)
};
describe('buildBenchmarkMarkdownReport', () => {
it('drops within-noise rows but keeps significant regressions', () => {
const report = compareBenchmarkReports(
makeReport({ Button: 150, Card: 105 }),
makeReport({ Button: 100, Card: 100 }),
);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).toContain('Button');
expect(markdown).not.toContain('Card');
expect(markdown).toContain('🔺');
});
it('renders "No significant changes" when every entry is within noise', () => {
const report = compareBenchmarkReports(
makeReport({ Button: 110, Card: 95 }),
makeReport({ Button: 100, Card: 100 }),
);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).toContain('No significant changes');
expect(markdown).not.toContain('| Test |');
});
it('includes the details link in the "No significant changes" branch', () => {
const report = compareBenchmarkReports(
makeReport({ Button: 110, Card: 95 }),
makeReport({ Button: 100, Card: 100 }),
);
const markdown = buildBenchmarkMarkdownReport(report, {
reportUrl: 'https://example.com/details',
});
expect(markdown).toContain('No significant changes');
expect(markdown).toContain('https://example.com/details');
});
it('shows "...and N more" footer once significant entries exceed maxRows', () => {
const current: Record<string, number> = {};
const base: Record<string, number> = {};
for (let i = 0; i < 7; i += 1) {
current[`Test${i}`] = 200;
base[`Test${i}`] = 100;
}
const report = compareBenchmarkReports(makeReport(current), makeReport(base));
const markdown = buildBenchmarkMarkdownReport(report, { maxRows: 5 });
expect(markdown).toContain('…and 2 more');
expect(markdown).not.toContain('within noise');
});
it('mentions within-noise tests in the footer when some entries are filtered out', () => {
const current: Record<string, number> = { Regression: 150 };
const base: Record<string, number> = { Regression: 100 };
for (let i = 0; i < 3; i += 1) {
current[`Stable${i}`] = 105;
base[`Stable${i}`] = 100;
}
const report = compareBenchmarkReports(makeReport(current), makeReport(base));
const markdown = buildBenchmarkMarkdownReport(report, {
maxRows: 5,
reportUrl: 'https://example.com/details',
});
expect(markdown).toContain('3 tests within noise');
expect(markdown).toContain('https://example.com/details');
});
it('combines truncated significant count with within-noise count when both apply', () => {
const current: Record<string, number> = {};
const base: Record<string, number> = {};
for (let i = 0; i < 7; i += 1) {
current[`Reg${i}`] = 200;
base[`Reg${i}`] = 100;
}
for (let i = 0; i < 4; i += 1) {
current[`Stable${i}`] = 105;
base[`Stable${i}`] = 100;
}
const report = compareBenchmarkReports(makeReport(current), makeReport(base));
const markdown = buildBenchmarkMarkdownReport(report, { maxRows: 5 });
expect(markdown).toContain('…and 2 more (+4 within noise)');
});
it('renders a plain table without totals or diff columns when hasBase is false', () => {
const report = compareBenchmarkReports(makeReport({ Button: 100 }), null);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).not.toContain('Total duration');
expect(markdown).not.toContain('🔺');
expect(markdown).not.toContain('▼');
expect(markdown).toContain('Button');
});
it('keeps removed entries visible even though their severity is neutral-like', () => {
const report = compareBenchmarkReports(makeReport({}), makeReport({ Button: 100 }));
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).toContain('~~Button~~');
expect(markdown).toContain('(removed)');
});
it('keeps rows whose render count changed even when the duration delta is within noise', () => {
const currentReport = makeReportFromConfig({
Button: { duration: 105, renders: 3 },
Card: { duration: 105, renders: 1 },
});
const baseReport = makeReportFromConfig({
Button: { duration: 100, renders: 1 },
Card: { duration: 100, renders: 1 },
});
const report = compareBenchmarkReports(currentReport, baseReport);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).toContain('Button');
expect(markdown).not.toContain('Card');
expect(markdown).toContain('🔺+2');
});
it('does not emit the "No significant changes" branch when only render counts change', () => {
const currentReport = makeReportFromConfig({
Button: { duration: 105, renders: 2 },
});
const baseReport = makeReportFromConfig({
Button: { duration: 100, renders: 1 },
});
const report = compareBenchmarkReports(currentReport, baseReport);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).not.toContain('No significant changes');
expect(markdown).toContain('| Test |');
});
describe('metric alarms', () => {
it('surfaces an error-level metric, making its otherwise-neutral test significant', () => {
const report = compareBenchmarkReports(
metricReport('clicks', 5, alarmDefinitions), // +2 vs 3, discrete error band 1
metricReport('clicks', 3),
);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).not.toContain('No significant changes');
expect(markdown).toContain('**Metric alarms**');
expect(markdown).toContain('| Bench | clicks |');
expect(markdown).toContain('🔺');
});
it('does not surface warning-level metrics (kept on the dashboard only)', () => {
const report = compareBenchmarkReports(
metricReport('tti', 115, alarmDefinitions), // +15%: past warn (10%), within error (25%) -> warning
metricReport('tti', 100),
);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).toContain('No significant changes');
expect(markdown).not.toContain('Metric alarms');
});
it('ignores informational metrics — no alarm section, test stays within noise', () => {
const report = compareBenchmarkReports(
metricReport('fps', 200, alarmDefinitions), // big change but no alarm configured
metricReport('fps', 100),
);
const markdown = buildBenchmarkMarkdownReport(report);
expect(markdown).toContain('No significant changes');
expect(markdown).not.toContain('Metric alarms');
});
});
});