|
1 |
| -import axios from "axios"; |
2 |
| - |
3 | 1 | export interface JSONResultData {
|
4 | 2 | min: number;
|
5 | 3 | max: number;
|
@@ -53,12 +51,12 @@ export interface BenchmarkOptions {
|
53 | 51 | HOST: 'localhost',
|
54 | 52 | */
|
55 | 53 |
|
56 |
| -export enum BENCHMARK_RUNNER { |
57 |
| - PUPPETEER = "puppeteer", |
58 |
| - PLAYWRIGHT = "playwright", |
59 |
| - WEBDRIVER_CDP = "webdrivercdp", |
| 54 | +export enum BENCHMARK_RUNNER { |
| 55 | + PUPPETEER = "puppeteer", |
| 56 | + PLAYWRIGHT = "playwright", |
| 57 | + WEBDRIVER_CDP = "webdrivercdp", |
60 | 58 | WEBDRIVER = "webdriver",
|
61 |
| - WEBDRIVER_AFTERFRAME = "webdriver-afterframe" |
| 59 | + WEBDRIVER_AFTERFRAME = "webdriver-afterframe" |
62 | 60 | }
|
63 | 61 |
|
64 | 62 | export let config = {
|
@@ -116,37 +114,63 @@ export interface IMatchPredicate {
|
116 | 114 |
|
117 | 115 | const matchAll: IMatchPredicate = () => true;
|
118 | 116 |
|
119 |
| -export async function initializeFrameworks(benchmarkOptions: BenchmarkOptions, matchPredicate: IMatchPredicate = matchAll): Promise<FrameworkData[]> { |
120 |
| - let lsResult ; |
| 117 | +async function fetchFrameworks(url: string) { |
| 118 | + try { |
| 119 | + const response = await fetch(url); |
| 120 | + |
| 121 | + if (!response.ok) { |
| 122 | + throw new Error(`Fetch error: ${response.statusText}`); |
| 123 | + } |
| 124 | + |
| 125 | + return await response.json(); |
| 126 | + } catch (error) { |
| 127 | + console.log(error); |
| 128 | + throw new Error(error); |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +export async function initializeFrameworks( |
| 133 | + benchmarkOptions: BenchmarkOptions, |
| 134 | + matchPredicate: IMatchPredicate = matchAll, |
| 135 | +): Promise<FrameworkData[]> { |
| 136 | + let lsResult; |
| 137 | + const lsUrl = `http://${benchmarkOptions.host}:${benchmarkOptions.port}/ls`; |
| 138 | + |
121 | 139 | try {
|
122 |
| - lsResult = ( |
123 |
| - // FIXME https://github.com/axios/axios/issues/5008 |
124 |
| - await (axios as any).get(`http://${benchmarkOptions.host}:${benchmarkOptions.port}/ls`) |
125 |
| - ).data; |
126 |
| - } catch (err) { |
127 |
| - console.log(err); |
128 |
| - console.log(`ERROR loading frameworks from http://${benchmarkOptions.host}:${benchmarkOptions.port}/ls. Is the server running?`); |
129 |
| - throw new Error(`ERROR loading frameworks from http://${benchmarkOptions.host}:${benchmarkOptions.port}/ls. Is the server running?`); |
| 140 | + lsResult = await fetchFrameworks(lsUrl); |
| 141 | + } catch (error) { |
| 142 | + throw new Error(error); |
130 | 143 | }
|
131 | 144 |
|
132 | 145 | let frameworks: FrameworkData[] = [];
|
133 | 146 | for (let ls of lsResult) {
|
134 | 147 | let frameworkVersionInformation: FrameworkInformation = ls;
|
135 |
| - let fullName = frameworkVersionInformation.type + "/" + frameworkVersionInformation.directory; |
| 148 | + let fullName = |
| 149 | + frameworkVersionInformation.type + |
| 150 | + "/" + |
| 151 | + frameworkVersionInformation.directory; |
136 | 152 | if (matchPredicate(fullName)) {
|
137 | 153 | frameworks.push({
|
138 |
| - name: frameworkVersionInformation.directory, |
139 |
| - fullNameWithKeyedAndVersion: frameworkVersionInformation.frameworkVersionString, |
140 |
| - uri: "frameworks/" + fullName + (frameworkVersionInformation.customURL ? frameworkVersionInformation.customURL : ""), |
141 |
| - keyed: frameworkVersionInformation.type === "keyed", |
142 |
| - useShadowRoot: !!frameworkVersionInformation.useShadowRoot, |
143 |
| - useRowShadowRoot: !!frameworkVersionInformation.useRowShadowRoot, |
144 |
| - shadowRootName: frameworkVersionInformation.shadowRootName, |
145 |
| - buttonsInShadowRoot: !!frameworkVersionInformation.buttonsInShadowRoot, |
146 |
| - issues: (frameworkVersionInformation.issues ?? []).map(i => Number(i)), |
147 |
| - frameworkHomeURL: frameworkVersionInformation.frameworkHomeURL ?? "" |
148 |
| - }); |
149 |
| - } |
| 154 | + name: frameworkVersionInformation.directory, |
| 155 | + fullNameWithKeyedAndVersion: |
| 156 | + frameworkVersionInformation.frameworkVersionString, |
| 157 | + uri: |
| 158 | + "frameworks/" + |
| 159 | + fullName + |
| 160 | + (frameworkVersionInformation.customURL |
| 161 | + ? frameworkVersionInformation.customURL |
| 162 | + : ""), |
| 163 | + keyed: frameworkVersionInformation.type === "keyed", |
| 164 | + useShadowRoot: !!frameworkVersionInformation.useShadowRoot, |
| 165 | + useRowShadowRoot: !!frameworkVersionInformation.useRowShadowRoot, |
| 166 | + shadowRootName: frameworkVersionInformation.shadowRootName, |
| 167 | + buttonsInShadowRoot: !!frameworkVersionInformation.buttonsInShadowRoot, |
| 168 | + issues: (frameworkVersionInformation.issues ?? []).map((i) => |
| 169 | + Number(i), |
| 170 | + ), |
| 171 | + frameworkHomeURL: frameworkVersionInformation.frameworkHomeURL ?? "", |
| 172 | + }); |
| 173 | + } |
150 | 174 | }
|
151 | 175 | if (config.LOG_DETAILS) {
|
152 | 176 | console.log("All available frameworks: ");
|
|
0 commit comments