-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathperformance_metrics.test.ts
73 lines (65 loc) · 2.08 KB
/
performance_metrics.test.ts
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
// @ts-nocheck
import {test, expect, createMap, waitFor} from '../util/vitest';
import {simulateDoubleTap} from '../util/simulate_interaction';
import land from '../util/fixtures/land.json';
import mapboxgl from '../../src/index';
test('Performance metrics collected', async () => {
const map = createMap({
interactive: true,
zoom: 1,
fadeDuration: 0,
center: [0, 0],
style: {
version: 8,
sources: {
land: {
type: 'geojson',
data: land
}
},
layers: [
{
id: 'background',
type: 'background',
paint: {
'background-color': '#72d0f2'
}
},
{
id: 'land',
type: 'fill',
source: 'land',
paint: {
'fill-color': '#f0e9e1'
}
}
]
}
});
await waitFor(map, 'load');
await simulateDoubleTap(map);
await waitFor(map, 'idle');
const performance = await new Promise((resolve, reject) => {
mapboxgl.getPerformanceMetricsAsync((err, result) => {
if (err) {
reject(err);
return;
}
resolve(result);
});
});
const timelines = performance.timelines;
expect(timelines.length).toEqual(3);
expect(timelines[0].scope).toEqual('Window');
expect(timelines[1].scope).toEqual('Worker');
expect(timelines[2].scope).toEqual('Worker');
const find = name => timelines[0].entries.find(e => e.name === name);
expect(timelines[0].entries.every(e => {
return !isNaN(e.startTime) && !isNaN(e.duration);
})).toBeTruthy();
expect(find('library-evaluate')).toBeTruthy();
expect(find('frame')).toBeTruthy();
expect(find('create')).toBeTruthy();
expect(find('load')).toBeTruthy();
expect(find('fullLoad')).toBeTruthy();
});