Skip to content

Commit 897e888

Browse files
authored
Merge pull request #2 from iFixit/add-query-param-to-urls
2 parents a82b4ce + f983100 commit 897e888

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"main": "dist/index.js",
66
"repository": "https://github.com/iFixit/vigilo.git",
77
"type": "module",
8+
"engines": {
9+
"node": ">=18.0.0"
10+
},
811
"scripts": {
912
"start": "node dist/index.js",
1013
"clean": "rm -rf dist",

Diff for: src/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ function retrieveDataPointsForAudits(results: Result, audits: string[]) {
4242
return values
4343
}
4444

45+
/**
46+
* Adds `rand={123..}` param to the urls to ensure we never hit a CDN cache.
47+
*/
48+
function addRandomParamToUrl(inspectList: Record<string, string[]>): Record<string, string[]> {
49+
const updatedInspectList: Record<string, string[]> = structuredClone(inspectList);
50+
51+
for (const pageType in updatedInspectList) {
52+
const urls = updatedInspectList[pageType];
53+
54+
updatedInspectList[pageType] = urls.map(url => {
55+
const urlObject = new URL(url);
56+
urlObject.searchParams.append('rand', Math.floor(Math.random() * 1000000).toString());
57+
return urlObject.toString();
58+
});
59+
}
60+
return updatedInspectList;
61+
}
62+
4563
async function sendMetricsToDatadog(metricName: string, dataPoints: v2.MetricPoint[], tags: Record<string, string>) {
4664
const dd = new Datadog({
4765
api_key: process.env.DD_API_KEY || '',
@@ -83,7 +101,8 @@ async function captureLighthouseMetrics(pageType: string, url: string, audits: s
83101
console.log(`Done running Lighthouse for ${url} with form factor: ${formFactor}\n`);
84102
}
85103
(async() => {
86-
const inspectList: Record<string, string[]> = JSON.parse(await fs.promises.readFile('urls.json', 'utf8'));
104+
let inspectList: Record<string, string[]> = JSON.parse(await fs.promises.readFile('urls.json', 'utf8'));
105+
inspectList = addRandomParamToUrl(inspectList);
87106

88107
const coreMetrics: Record<string, string[]> = JSON.parse(await fs.promises.readFile('metrics-config.json', 'utf8'));
89108

0 commit comments

Comments
 (0)