54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import {
|
|
describe,
|
|
it,
|
|
expect
|
|
} from 'vitest';
|
|
import {
|
|
formatPerfDiagLine,
|
|
pushRingBuffer,
|
|
resolveDiagnosticsFilePath
|
|
} from './diagnostics.rules';
|
|
|
|
describe('pushRingBuffer', () => {
|
|
it('appends items until capacity is reached', () => {
|
|
expect(pushRingBuffer([1, 2], 3, 4)).toEqual([
|
|
1,
|
|
2,
|
|
3
|
|
]);
|
|
});
|
|
|
|
it('drops the oldest items when capacity is exceeded', () => {
|
|
expect(pushRingBuffer([
|
|
1,
|
|
2,
|
|
3
|
|
], 4, 3)).toEqual([
|
|
2,
|
|
3,
|
|
4
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('formatPerfDiagLine', () => {
|
|
it('serializes one JSON object per line', () => {
|
|
const line = formatPerfDiagLine({
|
|
collectedAt: 1_700_000_000_000,
|
|
source: 'main',
|
|
type: 'process',
|
|
payload: { browserKb: 128 }
|
|
});
|
|
|
|
expect(line).toBe('{"collectedAt":1700000000000,"source":"main","type":"process","payload":{"browserKb":128}}');
|
|
expect(line.endsWith('\n')).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('resolveDiagnosticsFilePath', () => {
|
|
it('places session files under diagnostics/', () => {
|
|
expect(resolveDiagnosticsFilePath('/tmp/user-data', 'session-1'))
|
|
.toBe('/tmp/user-data/diagnostics/perf-session-1.jsonl');
|
|
});
|
|
});
|