forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance-navigation-timing.test.ts
More file actions
137 lines (128 loc) · 4.29 KB
/
Copy pathperformance-navigation-timing.test.ts
File metadata and controls
137 lines (128 loc) · 4.29 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
import { buildLinkClick, trackerCore } from '@snowplow/tracker-core';
import { JSDOM } from 'jsdom';
import { PerformanceNavigationTimingPlugin } from '../src';
declare var jsdom: JSDOM;
describe('Performance Navigation Timing plugin', () => {
it('Returns values for Performance Navigation Timing properties', (done) => {
const sampleNavigationTimingEntry = {
name: 'https://web.dev/navigation-and-resource-timing/#wrapping-up',
entryType: 'navigation',
startTime: 0,
duration: 1803.8000001907349,
initiatorType: 'navigation',
deliveryType: 'cache',
nextHopProtocol: 'h2',
renderBlockingStatus: 'blocking',
workerStart: 1,
redirectStart: 1,
redirectEnd: 1,
fetchStart: 18.200000286102295,
domainLookupStart: 25.90000009536743,
domainLookupEnd: 79,
connectStart: 79,
secureConnectionStart: 101.90000009536743,
connectEnd: 236.09999990463257,
requestStart: 236.09999990463257,
responseStart: 376.7000002861023,
responseEnd: 401.7000002861023,
transferSize: 11773,
encodedBodySize: 11473,
decodedBodySize: 59833,
responseStatus: 1,
serverTiming: [
{
description: 'test',
duration: 1900,
name: 'ttfb_estimate',
},
],
unloadEventStart: 1,
unloadEventEnd: 1,
domInteractive: 1077.5,
domContentLoadedEventStart: 1077.5999999046326,
domContentLoadedEventEnd: 1078.2000002861023,
domComplete: 1802.2000002861023,
loadEventStart: 1803.7000002861023,
loadEventEnd: 1803.8000001907349,
type: 'reload',
redirectCount: 1,
activationStart: 203.8,
};
Object.defineProperty(jsdom.window.performance, 'getEntriesByType', {
value: (entryType: string) => {
if (entryType === 'navigation') {
return [sampleNavigationTimingEntry];
}
return [];
},
configurable: true,
});
const core = trackerCore({
corePlugins: [PerformanceNavigationTimingPlugin()],
callback: (payloadBuilder) => {
const json = payloadBuilder.getJson().filter((e) => e.keyIfEncoded === 'cx');
expect(json[0].json).toMatchSnapshot();
done();
},
});
core.track(buildLinkClick({ targetUrl: 'https://example.com' }));
});
it('Returns values for Performance Navigation Timing properties removing empty or zero values', (done) => {
const sampleNavigationTimingEntry = {
name: 'https://web.dev/navigation-and-resource-timing/#wrapping-up',
entryType: 'navigation',
startTime: 0,
duration: 1803.8000001907349,
initiatorType: 'navigation',
deliveryType: 'cache',
nextHopProtocol: 'h2',
renderBlockingStatus: 'blocking',
workerStart: 0,
redirectStart: 0,
redirectEnd: 0,
fetchStart: 18.200000286102295,
domainLookupStart: 25.90000009536743,
domainLookupEnd: 79,
connectStart: 79,
secureConnectionStart: 101.90000009536743,
connectEnd: 236.09999990463257,
requestStart: 236.09999990463257,
responseStart: 376.7000002861023,
responseEnd: 401.7000002861023,
transferSize: 11773,
encodedBodySize: 11473,
decodedBodySize: 59833,
responseStatus: 0,
serverTiming: [],
unloadEventStart: 1,
unloadEventEnd: 1,
domInteractive: 1077.5,
domContentLoadedEventStart: 1077.5999999046326,
domContentLoadedEventEnd: 1078.2000002861023,
domComplete: 1802.2000002861023,
loadEventStart: 1803.7000002861023,
loadEventEnd: 1803.8000001907349,
type: 'reload',
redirectCount: 0,
activationStart: 0,
};
Object.defineProperty(jsdom.window.performance, 'getEntriesByType', {
value: (entryType: string) => {
if (entryType === 'navigation') {
return [sampleNavigationTimingEntry];
}
return [];
},
configurable: true,
});
const core = trackerCore({
corePlugins: [PerformanceNavigationTimingPlugin()],
callback: (payloadBuilder) => {
const json = payloadBuilder.getJson().filter((e) => e.keyIfEncoded === 'cx');
expect(json[0].json).toMatchSnapshot();
done();
},
});
core.track(buildLinkClick({ targetUrl: 'https://example.com' }));
});
});