Skip to content

Commit

Permalink
broken test script for u
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiteAFancyEmerald committed Jul 10, 2024
1 parent 2e17d5a commit fe11e62
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"helmet": "^7.1.0",
"mime-types": "^2.1.35",
"node-fetch": "^3.3.2",
"puppeteer": "^22.12.1",
"rammerhead": "https://github.com/NebulaServices/rammerhead/releases/download/rammerhead-1.2.41-nebula.8/rammerhead-1.2.41-nebula.7.tgz",
"wisp-server-node": "^1.1.0",
"ws": "^8.18.0"
Expand Down
147 changes: 136 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,145 @@
const axios = require("axios");
const axios = require('axios');
const puppeteer = require('puppeteer');

async function testEndpoint(url) {
try {
const response = await axios.get(url);
return response.status === 200;
} catch (error) {
console.error(`Error while testing ${url}:`, error.message);
return false;
}
}

async function testGeneratedUrl(url) {
try {
const response = await axios.get(url);
return response.status === 200;
} catch (error) {
console.error(`Error while testing generated URL ${url}:`, error.message);
return false;
}
}

async function testServerResponse() {
const endpoints = [
'http://localhost:8080/',
'http://localhost:8080/?pathtonowhere',
'http://localhost:8080/?browse',
'http://localhost:8080/?rh',
'http://localhost:8080/?q'
];

const results = await Promise.all(endpoints.map(testEndpoint));
const allPassed = results.every(result => result);

if (allPassed) {
console.log('All endpoints responded with status code 200. Test passed.');
await testCommonJSOnPage();
} else {
console.error('One or more endpoints failed to respond with status code 200. Test failed.');
process.exit(1); // Exit with failure
}
}

async function testCommonJSOnPage() {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();

try {
const response = await axios.get("http://localhost:8080/?pathtonowhere");
if (response.status === 200) {
console.log("Server responded with status code 200. Test passed.");
process.exit(0); // Exit with success
// Function to test Rammerhead with "?rh"
async function testRammerhead() {
await page.goto('http://localhost:8080/?rh');

const testResults = await page.evaluate(async () => {
const results = {};

// Wait for the DOM content to be fully loaded and goProx to be available
await new Promise(resolve => {
if (document.readyState === 'complete') {
resolve();
} else {
window.addEventListener('load', resolve);
}
});

if (window.goProx) {
// Test rammerhead with google.com
try {
const rammerheadUrl = await window.goProx.rammerhead('google.com', false);
results.rammerhead = rammerheadUrl ? rammerheadUrl : 'failure';
} catch (e) {
results.rammerhead = 'failure: ' + e.message;
}
} else {
results.goProx = 'not defined';
}

return results;
});

console.log('Rammerhead test results:', testResults);

const rammerheadTestPassed = testResults.rammerhead !== 'failure' && await testGeneratedUrl(testResults.rammerhead);

console.log(`Rammerhead test result: ${rammerheadTestPassed ? 'success' : 'failure'}`);

return rammerheadTestPassed;
}

// Function to test Ultraviolet with "?q"
async function testUltraviolet() {
await page.goto('http://localhost:8080/?q');

const testResults = await page.evaluate(async () => {
const results = {};

// Wait for the DOM content to be fully loaded and goProx to be available
await new Promise(resolve => {
if (document.readyState === 'complete') {
resolve();
} else {
window.addEventListener('load', resolve);
}
});

if (window.goProx) {
// Test ultraviolet with google.com
try {
const uvUrl = window.goProx.ultraviolet('google.com', false);
results.ultraviolet = uvUrl ? uvUrl : 'failure';
} catch (e) {
results.ultraviolet = 'failure: ' + e.message;
}
} else {
results.goProx = 'not defined';
}

return results;
});

console.log('Ultraviolet test results:', testResults);

const uvTestPassed = testResults.ultraviolet !== 'failure' && await testGeneratedUrl(testResults.ultraviolet);

console.log(`Ultraviolet test result: ${uvTestPassed ? 'success' : 'failure'}`);

return uvTestPassed;
}

// Run tests for Rammerhead and Ultraviolet
const rammerheadPassed = await testRammerhead();
const ultravioletPassed = await testUltraviolet();

if (rammerheadPassed && ultravioletPassed) {
console.log('Both tests passed.');
} else {
console.error(
`Expected status code 200 but received ${response.status}. Test failed.`
);
process.exit(1); // Exit with failure
console.error('Tests failed.');
}
} catch (error) {
console.error("Error while testing server response:", error.message);
process.exit(1); // Exit with failure
console.error('Error in testCommonJSOnPage:', error.message);
} finally {
await browser.close();
}
}

Expand Down

0 comments on commit fe11e62

Please sign in to comment.