forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrack_performance.test.ts
More file actions
executable file
·61 lines (50 loc) · 2.79 KB
/
Copy pathtrack_performance.test.ts
File metadata and controls
executable file
·61 lines (50 loc) · 2.79 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
import { Capabilities } from "@wdio/types";
const loadUrlAndWait = async (url: string) => {
await browser.url(url);
await browser.pause(5000);
await browser.waitUntil(async () => (await $('#init').getText()) === 'true', {
timeout: 20000,
timeoutMsg: 'expected init after 20s',
});
};
const shouldSkipBrowser = (browser: any) => {
const capabilities = browser.capabilities as Capabilities.DesiredCapabilities;
const browserName = capabilities.browserName?.toLowerCase();
return browserName === 'firefox' || browserName === 'safari';
};
describe('Performance of tracking', () => {
if (shouldSkipBrowser(browser)) {
fit('Skip browser', () => { });
return;
}
let noneMeasure: PerformanceMeasure | undefined;
let cookieMeasure: PerformanceMeasure | undefined;
let cookieAndLocalStorageMeasure: PerformanceMeasure | undefined;
let cookieAndLocalStorageSyncMeasure: PerformanceMeasure | undefined;
beforeAll(async () => {
await loadUrlAndWait('/track_performance.html?stateStorageStrategy=none');
noneMeasure = await browser.execute(() => performance.measure('none', 'start', 'end'));
await loadUrlAndWait('/track_performance.html?stateStorageStrategy=cookie');
cookieMeasure = await browser.execute(() => performance.measure('cookie', 'start', 'end'));
await loadUrlAndWait('/track_performance.html?stateStorageStrategy=cookieAndLocalStorage');
cookieAndLocalStorageMeasure = await browser.execute(() => performance.measure('cookieAndLocalStorage', 'start', 'end'));
await loadUrlAndWait('/track_performance.html?stateStorageStrategy=cookieAndLocalStorage&synchronousCookieWrite=true');
cookieAndLocalStorageSyncMeasure = await browser.execute(() => performance.measure('cookieAndLocalStorageSync', 'start', 'end'));
console.log('state storage strategy: none', noneMeasure?.duration);
console.log('state storage strategy: cookie', cookieMeasure?.duration);
console.log('state storage strategy: cookieAndLocalStorage', cookieAndLocalStorageMeasure?.duration);
console.log('state storage strategy: cookieAndLocalStorageSync', cookieAndLocalStorageSyncMeasure?.duration);
});
it('should have a performance log', () => {
expect(noneMeasure).toBeDefined();
expect(cookieMeasure).toBeDefined();
expect(cookieAndLocalStorageMeasure).toBeDefined();
expect(cookieAndLocalStorageSyncMeasure).toBeDefined();
});
it('should have a performance log with a duration', () => {
expect(noneMeasure?.duration).toBeLessThan(1000);
expect(cookieMeasure?.duration).toBeLessThan((noneMeasure?.duration ?? 0) * 2);
expect(cookieAndLocalStorageMeasure?.duration).toBeLessThan((cookieMeasure?.duration ?? 0) * 2);
expect(cookieAndLocalStorageSyncMeasure?.duration).toBeLessThan((cookieAndLocalStorageMeasure?.duration ?? 0) * 10);
});
});