Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

11 changes: 7 additions & 4 deletions lib/test/balancer/simple-balancer-with-websockets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ Simple round robin load balancer for websockets
pnpm test ./simple-balancer-with-websockets.test.ts
*/

import fetch from "node-fetch";
import { once } from "node:events";
import * as http from "node:http";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import * as httpProxy from "../..";
import getPort from "../get-port";
import { once } from "node:events";
import fetch from "node-fetch";

describe("A simple round-robin load balancer that supports websockets", () => {
let addresses: Array<{ host: string, port: number }>;
it("lists the servers to use in our rotation.", async () => {
beforeAll(async () => {
// lists the servers to use in our rotation.
addresses = [
{
host: "localhost",
Expand Down Expand Up @@ -121,7 +123,8 @@ describe("A simple round-robin load balancer that supports websockets", () => {
]);
});

it("cleans up", () => {
afterAll(async() => {
// cleans up
Object.values(servers).map((x: any) => x?.close());
});
});
7 changes: 5 additions & 2 deletions lib/test/balancer/simple-balancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import * as http from "node:http";
import * as httpProxy from "../..";
import getPort from "../get-port";
import fetch from "node-fetch";
import { describe, it, expect, afterAll, beforeAll } from "vitest";

describe("A simple round-robin load balancing strategy.", () => {
let addresses: Array<{ host: string, port: number }>;
it("lists the servers to use in our rotation.", async () => {
beforeAll(async () => {
// lists the servers to use in our rotation.
addresses = [
{
host: "localhost",
Expand Down Expand Up @@ -72,7 +74,8 @@ describe("A simple round-robin load balancing strategy.", () => {
]);
});

it("cleans up", () => {
afterAll(async () => {
// cleans up
Object.values(servers).map((x: any) => x?.close());
});
});
13 changes: 8 additions & 5 deletions lib/test/http/basic-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as httpProxy from "../..";
import log from "../log";
import getPort from "../get-port";
import fetch from "node-fetch";
import { describe, it, expect, afterAll, beforeAll } from "vitest";

export async function server() {
const httpPort = await getPort();
Expand All @@ -20,9 +21,9 @@ export async function server() {
res.writeHead(200, { "Content-Type": "text/plain" });
res.write(
"request successfully proxied to: " +
req.url +
"\n" +
JSON.stringify(req.headers, undefined, 2),
req.url +
"\n" +
JSON.stringify(req.headers, undefined, 2),
);
res.end();
});
Expand Down Expand Up @@ -61,7 +62,8 @@ describe("tests proxying a basic http server", () => {

describe("Load test against the basic proxy", () => {
let x: { proxy: httpProxy.ProxyServer; target: http.Server; httpPort: number; proxyPort: number };
it("creates servers", async () => {
beforeAll(async () => {
// creates servers
x = await server();
});

Expand Down Expand Up @@ -108,7 +110,8 @@ describe("Load test against the basic proxy", () => {
expect(elapsed).toBeLessThan(MAX_TIME);
});

it("Cleans up", () => {
afterAll(async () => {
// Cleans up
x.proxy.close();
x.target.close();
});
Expand Down
1 change: 1 addition & 0 deletions lib/test/http/custom-proxy-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as httpProxy from "../..";
import * as http from "node:http";
import getPort from "../get-port";
import fetch from "node-fetch";
import {describe, it, expect} from 'vitest';

const CUSTOM_ERROR =
"Something went wrong. And we are reporting a custom error message.";
Expand Down
1 change: 1 addition & 0 deletions lib/test/http/double-slashes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from "express";
import getPort from "../get-port";
import ProxyServer, { createServer } from "../..";
import http from "node:http";
import {describe, it, expect} from 'vitest';

// See https://github.com/sagemathinc/http-proxy-3/issues/6

Expand Down
1 change: 1 addition & 0 deletions lib/test/http/error-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as http from "node:http";
import getPort from "../get-port";
import log from "../log";
import fetch from "node-fetch";
import {describe, it, expect} from 'vitest';

const CUSTOM_ERROR = "There was an error proxying your request";

Expand Down
1 change: 1 addition & 0 deletions lib/test/http/forward-and-target-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import log from "../log";
import getPort from "../get-port";
import wait from "../wait";
import fetch from "node-fetch";
import {describe, it, expect} from 'vitest';

describe("Example of proxying over HTTP with additional forward proxy to a different server", () => {
let ports: Record<'target' | 'forward' | 'proxy', number>;
Expand Down
13 changes: 8 additions & 5 deletions lib/test/http/forward-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ import log from "../log";
import getPort from "../get-port";
import wait from "../wait";
import fetch from "node-fetch";
import { describe, it, expect, beforeAll, afterAll } from 'vitest';

describe("Example of proxying over HTTP with additional forward proxy", () => {
let forwardingServer: http.Server,
httpPort: number,
numRequests = 0;
it("Setup Target Http Forwarding Server", async () => {
beforeAll(async () => {
// Setup Target Http Forwarding Server
httpPort = await getPort();
forwardingServer = http.createServer((req, res) => {
log("Receiving forward for: " + req.url);
numRequests += 1;
res.writeHead(200, { "Content-Type": "text/plain" });
res.write(
"request successfully forwarded to: " +
req.url +
"\n" +
JSON.stringify(req.headers, undefined, 2),
req.url +
"\n" +
JSON.stringify(req.headers, undefined, 2),
);
res.end();
});
Expand Down Expand Up @@ -91,7 +93,8 @@ describe("Example of proxying over HTTP with additional forward proxy", () => {
expect(numRequests).toBe(before + 2);
});

it("Cleans up", () => {
afterAll(async () => {
// Cleans up
forwardingServer.close();
proxyServer.close();
proxy2Server.close();
Expand Down
1 change: 1 addition & 0 deletions lib/test/http/latent-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pnpm test latent-proxy.test.ts
import * as http from "node:http";
import * as httpProxy from "../..";
import getPort from "../get-port";
import {describe, it, expect} from 'vitest';

describe("Test proxying over HTTP with latency", () => {
let ports: Record<'http' | 'proxy', number>;
Expand Down
7 changes: 5 additions & 2 deletions lib/test/http/proxy-http-to-https.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import * as https from "node:https";
import * as httpProxy from "../..";
import getPort from "../get-port";
import fetch from "node-fetch";
import { describe, it, expect, beforeAll, afterAll } from 'vitest';

describe(" Basic example of proxying over HTTP to a target HTTPS server", () => {
let port: number, server: httpProxy.ProxyServer;
it("creates the proxy server with HTTPS target", async () => {
beforeAll(async () => {
// creates the proxy server with HTTPS target
port = await getPort();
server = httpProxy
.createProxyServer({
Expand All @@ -33,7 +35,8 @@ describe(" Basic example of proxying over HTTP to a target HTTPS server", () =>
expect(r).toContain("Search the world");
});

it("clean up", () => {
afterAll(async () => {
// clean up
server.close();
});
});
6 changes: 4 additions & 2 deletions lib/test/http/proxy-https-to-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import getPort from "../get-port";
import { join } from "node:path";
import { readFile } from "node:fs/promises";
import fetch from "node-fetch";
import {describe, it, expect, beforeAll, afterAll} from 'vitest';

const fixturesDir = join(__dirname, "..", "fixtures");

describe("Basic example of proxying over HTTPS to a target HTTP server", () => {
let ports: Record<'http' | 'proxy', number>;
it("Gets ports", async () => {
beforeAll(async () => {
ports = { http: await getPort(), proxy: await getPort() };
});

Expand Down Expand Up @@ -54,7 +55,8 @@ describe("Basic example of proxying over HTTPS to a target HTTP server", () => {
expect(r).toContain("hello http over https");
});

it("cleans up", () => {
afterAll(async () => {
// cleans up
Object.values(servers).map((x: any) => x?.close());
});
});
7 changes: 5 additions & 2 deletions lib/test/http/proxy-https-to-https.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import getPort from "../get-port";
import { join } from "node:path";
import { readFile } from "node:fs/promises";
import fetch from "node-fetch";
import { describe, it, expect, beforeAll, afterAll } from 'vitest';

const fixturesDir = join(__dirname, "..", "fixtures");

describe("Basic example of proxying over HTTPS to a target HTTPS server", () => {
let ports: Record<'https' | 'proxy', number>;
it("Gets ports", async () => {
beforeAll(async () => {
// Gets ports
ports = { https: await getPort(), proxy: await getPort() };
});

Expand Down Expand Up @@ -56,7 +58,8 @@ describe("Basic example of proxying over HTTPS to a target HTTPS server", () =>
expect(r).toContain("hello over https");
});

it("cleans up", () => {
afterAll(async () => {
// cleanup
Object.values(servers).map((x: any) => x?.close());
});
});
7 changes: 5 additions & 2 deletions lib/test/http/reverse-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import * as net from "node:net";
import log from "../log";
import { HttpsProxyAgent } from "https-proxy-agent";
import fetch from "node-fetch";
import { describe, it, expect, afterAll, beforeAll } from 'vitest';

describe("Reverse proxying -- create a server that...", () => {
let port: number;
it("allocates a port", async () => {
beforeAll(async () => {
// allocates a port
port = await getPort();
});

Expand Down Expand Up @@ -77,7 +79,8 @@ describe("Reverse proxying -- create a server that...", () => {
expect(a).toContain("Search the world");
});

it("Cleans up", () => {
afterAll(async () => {
// Cleans up
server.close();
});
});
1 change: 1 addition & 0 deletions lib/test/http/server-sent-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import getPort from "../get-port";
import { createSession } from "better-sse";
import { EventSource } from "eventsource";
import fetch from "node-fetch";
import {describe, it, expect} from 'vitest';

describe("proxying server sent events over HTTP", () => {
let ports: Record<'http' | 'proxy', number>;
Expand Down
1 change: 1 addition & 0 deletions lib/test/lib/http-proxy-common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
setupSocket,
} from "../../http-proxy/common";
import net from 'net';
import {describe, it, expect} from 'vitest';

// wrap setupOutgoing so types aren't checked, since a lot of the tests here
// involve partial objects that typescript doesn't view as correct, e.g., {url:'foo...'}
Expand Down
Loading
Loading