-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathparse.test.ts
More file actions
43 lines (38 loc) · 1.42 KB
/
parse.test.ts
File metadata and controls
43 lines (38 loc) · 1.42 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
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {describe, it} from 'node:test';
import assert from 'node:assert';
import {
insightOutput,
parseRawTraceBuffer,
} from '../../src/trace-processing/parse.js';
import {loadTraceAsBuffer} from './fixtures/load.js';
describe('Trace parsing', async () => {
it.snapshot.setResolveSnapshotPath(testPath => {
// By default the snapshots go into the build directory, but we want them
// in the tests/ directory.
const correctPath = testPath?.replace('/build/tests', '/tests');
return correctPath + '.snapshot';
});
// The default serializer is JSON.stringify which outputs a very hard to read
// snapshot. So we override it to one that shows new lines literally rather
// than via `\n`.
it.snapshot.setDefaultSnapshotSerializers([String]);
it('can parse a Uint8Array from Tracing.stop())', async () => {
const rawData = loadTraceAsBuffer('basic-trace.json.gz');
const result = await parseRawTraceBuffer(rawData);
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);
assert.ok(result?.parsedTrace);
assert.ok(result?.insights);
const output = insightOutput(result);
t.assert.snapshot(output);
});
});