-
Notifications
You must be signed in to change notification settings - Fork 844
/
Copy pathcommon.ts
184 lines (163 loc) · 4.95 KB
/
common.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
export interface JsonResultData {
min: number;
max: number;
mean: number;
stddev: number;
median: number;
values: Array<number>;
}
export interface JsonResultMap {
[key: string]: JsonResultData;
}
export interface JsonResult {
framework: string;
keyed: boolean;
benchmark: string;
type: string;
values: JsonResultMap;
}
export type BenchmarkStatus = "OK" | "TEST_FAILED" | "TECHNICAL_ERROR";
export interface ErrorAndWarning<T> {
error?: string;
warnings?: string[];
result?: T[];
}
export interface BenchmarkOptions {
host: string;
port: number;
headless?: boolean;
chromeBinaryPath?: string;
remoteDebuggingPort: number;
chromePort: number;
batchSize: number;
browser: string;
numIterationsForCPUBenchmarks: number;
numIterationsForMemBenchmarks: number;
numIterationsForStartupBenchmark: number;
numIterationsForSizeBenchmark: number;
allowThrottling: boolean;
resultsDirectory: string;
tracesDirectory: string;
puppeteerSleep?: number;
}
/*
RESULTS_DIRECTORY: "results",
TRACES_DIRECTORY: "traces",
BROWSER: "chrome",
HOST: 'localhost',
*/
export enum BenchmarkRunner {
PUPPETEER = "puppeteer",
PLAYWRIGHT = "playwright",
WEBDRIVER_CDP = "webdrivercdp",
WEBDRIVER_AFTERFRAME = "webdriver-afterframe",
}
export let config = {
NUM_ITERATIONS_FOR_BENCHMARK_CPU: 15,
NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT: 0, // drop the # of slowest results
NUM_ITERATIONS_FOR_BENCHMARK_MEM: 1,
NUM_ITERATIONS_FOR_BENCHMARK_STARTUP: 1,
NUM_ITERATIONS_FOR_BENCHMARK_SIZE: 1,
TIMEOUT: 60 * 1000,
LOG_PROGRESS: true,
LOG_DETAILS: false,
LOG_DEBUG: false,
LOG_TIMELINE: false,
EXIT_ON_ERROR: null as boolean, // set from command line
STARTUP_DURATION_FROM_EVENTLOG: true,
STARTUP_SLEEP_DURATION: 1000,
WRITE_RESULTS: true,
ALLOW_BATCHING: true,
BENCHMARK_RUNNER: BenchmarkRunner.PUPPETEER,
PUPPETEER_WAIT_MS: 0,
};
export type Config = typeof config;
export interface FrameworkData {
name: string;
fullNameWithKeyedAndVersion: string;
uri: string;
keyed: boolean;
useShadowRoot: boolean;
useRowShadowRoot: boolean;
shadowRootName: string | undefined;
buttonsInShadowRoot: boolean;
startLogicEventName: string;
issues: number[];
frameworkHomeURL: string;
}
type KeyedType = "keyed" | "non-keyed";
export interface FrameworkInformation {
type: KeyedType;
directory: string;
issues: string[];
customURL?: string;
useShadowRoot?: boolean;
useRowShadowRoot?: boolean;
shadowRootName?: string;
buttonsInShadowRoot?: boolean;
versions?: { [key: string]: string };
frameworkVersionString: string;
frameworkHomeURL: string;
startLogicEventName: string;
}
export interface MatchPredicate {
(frameworkDirectory: string): boolean;
}
const matchAll: MatchPredicate = () => true;
async function fetchFrameworks(url: string) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Fetch error: ${response.statusText}`);
}
return await response.json();
} catch (error) {
console.log(error);
throw new Error(error as string);
}
}
export async function initializeFrameworks(
benchmarkOptions: BenchmarkOptions,
matchPredicate: MatchPredicate = matchAll
): Promise<FrameworkData[]> {
let lsResult;
const lsUrl = `http://${benchmarkOptions.host}:${benchmarkOptions.port}/ls`;
try {
lsResult = await fetchFrameworks(lsUrl);
} catch (error) {
throw new Error(error as string);
}
let frameworks: FrameworkData[] = [];
for (let ls of lsResult) {
let frameworkVersionInformation: FrameworkInformation = ls;
let fullName = frameworkVersionInformation.type + "/" + frameworkVersionInformation.directory;
if (matchPredicate(fullName)) {
frameworks.push({
name: frameworkVersionInformation.directory,
fullNameWithKeyedAndVersion: frameworkVersionInformation.frameworkVersionString,
uri:
"frameworks/" +
fullName +
(frameworkVersionInformation.customURL ? frameworkVersionInformation.customURL : ""),
keyed: frameworkVersionInformation.type === "keyed",
useShadowRoot: !!frameworkVersionInformation.useShadowRoot,
useRowShadowRoot: !!frameworkVersionInformation.useRowShadowRoot,
shadowRootName: frameworkVersionInformation.shadowRootName,
buttonsInShadowRoot: !!frameworkVersionInformation.buttonsInShadowRoot,
issues: (frameworkVersionInformation.issues ?? []).map(Number),
frameworkHomeURL: frameworkVersionInformation.frameworkHomeURL ?? "",
startLogicEventName: frameworkVersionInformation.startLogicEventName
});
}
}
if (config.LOG_DETAILS) {
console.log("All available frameworks: ");
console.log(frameworks.map((fd) => fd.fullNameWithKeyedAndVersion));
}
return frameworks;
}
export const wait = (delay = 1000) => {
console.log(`Waiting for ${delay} ms`);
if (delay === 0) return Promise.resolve();
else return new Promise((res) => setTimeout(res, delay));
};