Skip to content

Commit 74b033d

Browse files
committed
Minor reformatting and commenting for test script.
1 parent 8e32436 commit 74b033d

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

test.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const axios = require("axios");
22
const puppeteer = require("puppeteer");
33

4-
async function testEndpoint(url) {
4+
const testEndpoint = async url => {
55
try {
66
const response = await axios.get(url);
77
return response.status === 200;
88
} catch (error) {
99
console.error(`Error while testing ${url}:`, error.message);
1010
return false;
1111
}
12-
}
12+
};
1313

14-
async function testGeneratedUrl(url, headers) {
14+
const testGeneratedUrl = async (url, headers) => {
1515
try {
1616
console.log(`Testing generated URL: ${url}`);
1717

@@ -22,9 +22,9 @@ async function testGeneratedUrl(url, headers) {
2222
console.error(`Error while testing generated URL ${url}:`, error.message);
2323
return false;
2424
}
25-
}
25+
};
2626

27-
async function testServerResponse() {
27+
const testServerResponse = async () => {
2828
const endpoints = [
2929
"http://localhost:8080/",
3030
"http://localhost:8080/?pathtonowhere",
@@ -45,9 +45,9 @@ async function testServerResponse() {
4545
);
4646
process.exit(1);
4747
}
48-
}
48+
};
4949

50-
async function testCommonJSOnPage() {
50+
const testCommonJSOnPage = async () => {
5151
const browser = await puppeteer.launch({
5252
args: [
5353
"--enable-features=NetworkService",
@@ -60,16 +60,16 @@ async function testCommonJSOnPage() {
6060
const page = await browser.newPage();
6161

6262
try {
63-
async function getHeaders() {
63+
const getHeaders = async () => {
6464
const headers = {};
6565

6666
headers["User-Agent"] = await page.evaluate(() => navigator.userAgent);
6767
headers["Referer"] = await page.evaluate(() => window.location.href);
6868

6969
return headers;
70-
}
70+
};
7171

72-
async function testRammerhead() {
72+
const testRammerhead = async () => {
7373
await page.goto("http://localhost:8080/?rh");
7474

7575
const testResults = await page.evaluate(async () => {
@@ -115,7 +115,7 @@ async function testCommonJSOnPage() {
115115
);
116116

117117
return rammerheadTestPassed;
118-
}
118+
};
119119

120120
/*
121121
@@ -155,7 +155,7 @@ xx xx
155155

156156

157157

158-
async function testUltraviolet() {
158+
const testUltraviolet = async () => {
159159
await page.goto("http://localhost:8080/?q");
160160

161161
const testResults = await page.evaluate(async () => {
@@ -179,10 +179,15 @@ xx xx
179179
});
180180

181181
if (window.goProx && window.goProx.ultraviolet) {
182+
// For the hacky URL test, use the URL page's EXACT title.
183+
const website = {
184+
path: "example.com",
185+
title: "Example Domain"
186+
};
187+
182188
try {
183-
// For the hacky URL test, keep this as example.com.
184189
const generatedUrl = window.goProx.ultraviolet(
185-
"example.com",
190+
website.path,
186191
false
187192
);
188193
console.log("Generated Ultraviolet URL:", generatedUrl);
@@ -193,13 +198,15 @@ xx xx
193198
const testGeneratedUrlHacky = async (url) => {
194199
let result = false;
195200
const exampleIFrame = document.createElement("iframe");
196-
const waitForDocument = new Promise(resolve => exampleIFrame.addEventListener("load", () => {
197-
result = exampleIFrame.contentWindow.document.title === "Example Domain";
201+
const waitForDocument = new Promise(resolve => {
202+
document.documentElement.appendChild(exampleIFrame);
203+
exampleIFrame.addEventListener("load", () => {
204+
result = exampleIFrame.contentWindow.document.title === website.title;
198205
resolve();
199-
}));
206+
});
207+
});
200208
exampleIFrame.src = url;
201209
exampleIFrame.style.display = "none";
202-
document.documentElement.appendChild(exampleIFrame);
203210
await waitForDocument;
204211
return result;
205212
};
@@ -227,7 +234,7 @@ xx xx
227234
console.log(`Ultraviolet test result: failure`);
228235
return false;
229236
}
230-
}
237+
};
231238

232239
// Run tests for Rammerhead and Ultraviolet
233240
const rammerheadPassed = await testRammerhead();
@@ -246,6 +253,6 @@ xx xx
246253
} finally {
247254
await browser.close();
248255
}
249-
}
256+
};
250257

251258
testServerResponse();

0 commit comments

Comments
 (0)