Skip to content

Commit 4d1408f

Browse files
committed
feat: replace jest with vitest
- replace jest with vitest - replace jest.config.js with vitest.config.js - reuse setup file - remove jest-related dependencies
1 parent c3da184 commit 4d1408f

34 files changed

+1068
-2372
lines changed

jest.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/test/balancer/simple-balancer-with-websockets.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ Simple round robin load balancer for websockets
44
pnpm test ./simple-balancer-with-websockets.test.ts
55
*/
66

7+
import fetch from "node-fetch";
8+
import { once } from "node:events";
79
import * as http from "node:http";
10+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
811
import * as httpProxy from "../..";
912
import getPort from "../get-port";
10-
import { once } from "node:events";
11-
import fetch from "node-fetch";
1213

1314
describe("A simple round-robin load balancer that supports websockets", () => {
1415
let addresses: Array<{ host: string, port: number }>;
15-
it("lists the servers to use in our rotation.", async () => {
16+
beforeAll(async () => {
17+
// lists the servers to use in our rotation.
1618
addresses = [
1719
{
1820
host: "localhost",
@@ -121,7 +123,8 @@ describe("A simple round-robin load balancer that supports websockets", () => {
121123
]);
122124
});
123125

124-
it("cleans up", () => {
126+
afterAll(async() => {
127+
// cleans up
125128
Object.values(servers).map((x: any) => x?.close());
126129
});
127130
});

lib/test/balancer/simple-balancer.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import * as http from "node:http";
88
import * as httpProxy from "../..";
99
import getPort from "../get-port";
1010
import fetch from "node-fetch";
11+
import { describe, it, expect, afterAll, beforeAll } from "vitest";
1112

1213
describe("A simple round-robin load balancing strategy.", () => {
1314
let addresses: Array<{ host: string, port: number }>;
14-
it("lists the servers to use in our rotation.", async () => {
15+
beforeAll(async () => {
16+
// lists the servers to use in our rotation.
1517
addresses = [
1618
{
1719
host: "localhost",
@@ -72,7 +74,8 @@ describe("A simple round-robin load balancing strategy.", () => {
7274
]);
7375
});
7476

75-
it("cleans up", () => {
77+
afterAll(async () => {
78+
// cleans up
7679
Object.values(servers).map((x: any) => x?.close());
7780
});
7881
});

lib/test/http/basic-proxy.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as httpProxy from "../..";
1111
import log from "../log";
1212
import getPort from "../get-port";
1313
import fetch from "node-fetch";
14+
import { describe, it, expect, afterAll, beforeAll } from "vitest";
1415

1516
export async function server() {
1617
const httpPort = await getPort();
@@ -20,9 +21,9 @@ export async function server() {
2021
res.writeHead(200, { "Content-Type": "text/plain" });
2122
res.write(
2223
"request successfully proxied to: " +
23-
req.url +
24-
"\n" +
25-
JSON.stringify(req.headers, undefined, 2),
24+
req.url +
25+
"\n" +
26+
JSON.stringify(req.headers, undefined, 2),
2627
);
2728
res.end();
2829
});
@@ -61,7 +62,8 @@ describe("tests proxying a basic http server", () => {
6162

6263
describe("Load test against the basic proxy", () => {
6364
let x: { proxy: httpProxy.ProxyServer; target: http.Server; httpPort: number; proxyPort: number };
64-
it("creates servers", async () => {
65+
beforeAll(async () => {
66+
// creates servers
6567
x = await server();
6668
});
6769

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

111-
it("Cleans up", () => {
113+
afterAll(async () => {
114+
// Cleans up
112115
x.proxy.close();
113116
x.target.close();
114117
});

lib/test/http/custom-proxy-error.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as httpProxy from "../..";
88
import * as http from "node:http";
99
import getPort from "../get-port";
1010
import fetch from "node-fetch";
11+
import {describe, it, expect} from 'vitest';
1112

1213
const CUSTOM_ERROR =
1314
"Something went wrong. And we are reporting a custom error message.";

lib/test/http/double-slashes.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import express from "express";
22
import getPort from "../get-port";
33
import ProxyServer, { createServer } from "../..";
44
import http from "node:http";
5+
import {describe, it, expect} from 'vitest';
56

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

lib/test/http/error-handling.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as http from "node:http";
77
import getPort from "../get-port";
88
import log from "../log";
99
import fetch from "node-fetch";
10+
import {describe, it, expect} from 'vitest';
1011

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

lib/test/http/forward-and-target-proxy.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import log from "../log";
1313
import getPort from "../get-port";
1414
import wait from "../wait";
1515
import fetch from "node-fetch";
16+
import {describe, it, expect} from 'vitest';
1617

1718
describe("Example of proxying over HTTP with additional forward proxy to a different server", () => {
1819
let ports: Record<'target' | 'forward' | 'proxy', number>;

lib/test/http/forward-proxy.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@ import log from "../log";
1515
import getPort from "../get-port";
1616
import wait from "../wait";
1717
import fetch from "node-fetch";
18+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
1819

1920
describe("Example of proxying over HTTP with additional forward proxy", () => {
2021
let forwardingServer: http.Server,
2122
httpPort: number,
2223
numRequests = 0;
23-
it("Setup Target Http Forwarding Server", async () => {
24+
beforeAll(async () => {
25+
// Setup Target Http Forwarding Server
2426
httpPort = await getPort();
2527
forwardingServer = http.createServer((req, res) => {
2628
log("Receiving forward for: " + req.url);
2729
numRequests += 1;
2830
res.writeHead(200, { "Content-Type": "text/plain" });
2931
res.write(
3032
"request successfully forwarded to: " +
31-
req.url +
32-
"\n" +
33-
JSON.stringify(req.headers, undefined, 2),
33+
req.url +
34+
"\n" +
35+
JSON.stringify(req.headers, undefined, 2),
3436
);
3537
res.end();
3638
});
@@ -91,7 +93,8 @@ describe("Example of proxying over HTTP with additional forward proxy", () => {
9193
expect(numRequests).toBe(before + 2);
9294
});
9395

94-
it("Cleans up", () => {
96+
afterAll(async () => {
97+
// Cleans up
9598
forwardingServer.close();
9699
proxyServer.close();
97100
proxy2Server.close();

lib/test/http/latent-proxy.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pnpm test latent-proxy.test.ts
55
import * as http from "node:http";
66
import * as httpProxy from "../..";
77
import getPort from "../get-port";
8+
import {describe, it, expect} from 'vitest';
89

910
describe("Test proxying over HTTP with latency", () => {
1011
let ports: Record<'http' | 'proxy', number>;

0 commit comments

Comments
 (0)