Skip to content

Commit

Permalink
Fixed issue with performance.now() function
Browse files Browse the repository at this point in the history
  • Loading branch information
karelkryda committed Dec 10, 2021
1 parent 8541363 commit d4dd072
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "universal-speedtest",
"version": "2.0.1",
"version": "2.0.2",
"description": "This library allows you to test speed with various speed testing sites.",
"main": "dist/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/Cloudflare.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {performance} from "perf_hooks";
import {HttpClientResponse, IncomingHttpHeaders} from "urllib";
import {createRequest} from "./helpers/UrllibHelper";
import {avg, convertUnits, getDistance, getQuartile, jitter, sortObject} from "./Utils";
Expand Down
1 change: 1 addition & 0 deletions src/Speedtest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {performance} from "perf_hooks";
import * as path from "path";
import {Worker} from "worker_threads";
import {IncomingHttpHeaders} from "urllib";
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/UrllibHelper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {performance} from "perf_hooks";
import {HttpClientResponse, IncomingHttpHeaders, request} from "urllib";
import {parseString} from "xml2js";
import {validate} from "fast-xml-parser";
Expand All @@ -14,7 +15,7 @@ import {validate} from "fast-xml-parser";
* @returns Promise
*/
export function createRequest(url: string, headers: IncomingHttpHeaders, secure = true, data = {}, bump = "0", timeout = 10, withBump = false): Promise<HttpClientResponse<unknown>> {
headers["user-agent"] = "Mozilla/5.0 (" + process.platform + "; U; " + process.arch + "; en-us) TypeScript/" + process.version + " (KHTML, like Gecko) UniversalSpeedTest/2.0.1";
headers["user-agent"] = "Mozilla/5.0 (" + process.platform + "; U; " + process.arch + "; en-us) TypeScript/" + process.version + " (KHTML, like Gecko) UniversalSpeedTest/2.0.2";
headers["cache-control"] = "no-cache";

return request(((url[0] == ":") ? (secure) ? "https" : "http" : "") + url + ((withBump) ? (((url.includes("?")) ? "&" : "?") + "x=" + performance.now() + bump) : ""), {
Expand Down
1 change: 1 addition & 0 deletions src/thread_workers/download_worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {performance} from "perf_hooks";
import {parentPort, workerData} from "worker_threads";
import {createRequest} from "../helpers/UrllibHelper";
import {HTTPDownloader} from "../helpers/HTTPDownloader";
Expand Down
1 change: 1 addition & 0 deletions src/thread_workers/upload_worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {performance} from "perf_hooks";
import {parentPort, workerData} from "worker_threads";
import {createRequest} from "../helpers/UrllibHelper";
import {HTTPUploader} from "../helpers/HTTPUploader";
Expand Down
2 changes: 1 addition & 1 deletion tests/Cloudflare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ describe("Cloudflare test", () => {
expect(result.ping).to.be.below(60);
expect(result.uploadSpeed).not.to.be.undefined;
expect(result.downloadSpeed).to.be.above(20);
}).timeout(90000);
}).timeout(120000);
});
2 changes: 1 addition & 1 deletion tests/Speedtest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ describe("Speedtest test", () => {
expect(result.ping).to.be.below(60);
expect(result.uploadSpeed).to.be.undefined;
expect(result.downloadSpeed).to.be.above(20);
}).timeout(90000);
}).timeout(120000);
});

0 comments on commit d4dd072

Please sign in to comment.