-
Notifications
You must be signed in to change notification settings - Fork 3
/
bulk-tests.js
66 lines (60 loc) · 1.61 KB
/
bulk-tests.js
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
import WebPageTest from "webpagetest";
const wptServer = "https://www.webpagetest.org";
const wpt = new WebPageTest(wptServer, "YOUR_API_KEY");
const finalResults = [];
// Your list of URLs to test
let urls = [
"https://www.webpagetest.org/",
"https://www.product.webpagetest.org/api",
"https://docs.webpagetest.org/api/",
"https://blog.webpagetest.org/",
"https://www.webpagetest.org/about",
];
let options = {
firstViewOnly: true,
location: "Dulles:Chrome",
connectivity: "4G",
pollResults: 5,
timeout: 240,
};
const runTest = (wpt, url, options) => {
return new Promise((resolve, reject) => {
console.log(`Submitting test for ${url}...`);
wpt.runTest(url, options, async (err, result) => {
try {
if (result) {
return resolve(result);
} else {
return reject(err);
}
} catch (e) {
console.info(e);
}
});
});
};
(async function () {
Promise.all(
urls.map(async (url) => {
try {
await runTest(wpt, url, options).then(async (result) => {
if (result.data) {
let median = result.data.median.firstView;
//Pushing the data into the Array
finalResults.push({
id: result.data.id,
url: result.data.url,
cls: median["chromeUserTiming.CumulativeLayoutShift"],
lcp: median["chromeUserTiming.LargestContentfulPaint"],
tbt: median["TotalBlockingTime"],
});
}
});
} catch (e) {
console.error(e);
}
})
).then(() => {
console.info(finalResults);
});
})();