Skip to content

Commit

Permalink
better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MBR-0001 committed Jan 1, 2021
1 parent 3bd831a commit e9e0e50
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
run: npm install

- name: Run test
run: npm test preflight
run: npm test
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"url": "https://github.com/MBR-0001/sourcequery/issues"
},
"homepage": "https://github.com/MBR-0001/sourcequery#readme",
"dependencies": {}
"dependencies": {},
"devDependencies": {
"node-fetch": "^2.6.1"
}
}
30 changes: 18 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
const fetch = require("node-fetch");
const SourceQuery = require("./index");

let servers = [
"139.99.124.97:28075",
"2.59.135.79:2303",
//"216.52.148.47:27015",
//"145.239.205.157:28016"
];

async function TestServer(ip) {
let split = ip.split(":");
const query = new SourceQuery(split[0], split[1], process.env.CI_TIMEOUT || 5e3);
Expand All @@ -26,16 +20,28 @@ async function TestServers(log = false, preflight = false) {
console.log("Starting test, CI: " + !!process.env.CI);

let failed = [];
let servers = await fetch("https://api.mbr.pw/api/steamquery/tests").then(r => r.json());

for (let server of servers) {
if (server.address == "Unknown") {
server.invalid = true;
failed.push(server.name + " failed (no IP)");
}
}

if (preflight) {
for (let server of servers) {
let s = server.split(":");
await SourceQuery.preflightCheck(s[0], s[1]).catch(x => failed.push(server + " - " + x));
for (let server of servers.filter(x => !x.invalid)) {
let s = server.address.split(":");
await SourceQuery.preflightCheck(s[0], s[1]).then(() => server.pass = true).catch(x => {
if (server.broken.some(i => x.includes(i))) return;
failed.push("Preflight failed for " + server.address + " (" + server.name + ") - " + x);
});
}
}

for (let server of servers) {
await TestServer(server).then(x => { if (log) console.log(x); }).catch(x => failed.push(server + " - " + x));
for (let server of servers.filter(x => !x.invalid && (x.pass || !preflight))) {
console.log(server);
await TestServer(server.address).then(x => { if (log) console.log(x); }).catch(x => failed.push(server.address + " (" + server.name + ") - " + x));
}

console.log("Test finished");
Expand Down

0 comments on commit e9e0e50

Please sign in to comment.