-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathparse.test.ts
More file actions
95 lines (77 loc) · 2.65 KB
/
parse.test.ts
File metadata and controls
95 lines (77 loc) · 2.65 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
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it} from 'node:test';
import {
getTraceSummary,
parseRawTraceBuffer,
rateCLS,
rateTimingMetric,
} from '../../src/trace-processing/parse.js';
import '../../src/DevtoolsUtils.js';
import {loadTraceAsBuffer} from './fixtures/load.js';
describe('Trace parsing', async () => {
it('can parse a Uint8Array from Tracing.stop())', async () => {
const rawData = loadTraceAsBuffer('basic-trace.json.gz');
const result = await parseRawTraceBuffer(rawData);
if ('error' in result) {
assert.fail(`Unexpected parse failure: ${result.error}`);
}
assert.ok(result?.parsedTrace);
assert.ok(result?.insights);
});
it('can format results of a trace', async t => {
const rawData = loadTraceAsBuffer('web-dev-with-commit.json.gz');
const result = await parseRawTraceBuffer(rawData);
if ('error' in result) {
assert.fail(`Unexpected parse failure: ${result.error}`);
}
assert.ok(result?.parsedTrace);
assert.ok(result?.insights);
const output = getTraceSummary(result);
t.assert.snapshot?.(output);
});
describe('rateTimingMetric', () => {
it('rates fast LCP as good', () => {
assert.strictEqual(rateTimingMetric('LCP', 1500), 'good');
});
it('rates moderate LCP as needs-improvement', () => {
assert.strictEqual(rateTimingMetric('LCP', 3000), 'needs-improvement');
});
it('rates slow LCP as poor', () => {
assert.strictEqual(rateTimingMetric('LCP', 5000), 'poor');
});
it('rates fast INP as good', () => {
assert.strictEqual(rateTimingMetric('INP', 100), 'good');
});
it('rates FCP at boundary as needs-improvement', () => {
assert.strictEqual(rateTimingMetric('FCP', 2500), 'needs-improvement');
});
it('rates fast TTFB as good', () => {
assert.strictEqual(rateTimingMetric('TTFB', 500), 'good');
});
it('returns null for unknown metrics', () => {
assert.strictEqual(rateTimingMetric('UNKNOWN', 100), null);
});
});
describe('rateCLS', () => {
it('rates low CLS as good', () => {
assert.strictEqual(rateCLS(0.05), 'good');
});
it('rates moderate CLS as needs-improvement', () => {
assert.strictEqual(rateCLS(0.15), 'needs-improvement');
});
it('rates high CLS as poor', () => {
assert.strictEqual(rateCLS(0.30), 'poor');
});
});
it('will return a message if there is an error', async () => {
const result = await parseRawTraceBuffer(undefined);
assert.deepEqual(result, {
error: 'No buffer was provided.',
});
});
});