Skip to content

Commit 28af6f7

Browse files
committed
Merge branch 'hereje-feat/migrate-jest-to-vitest'
2 parents 7120b55 + 6e68d76 commit 28af6f7

35 files changed

+1069
-2371
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ jobs:
2828
matrix:
2929
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
3030
node-version:
31-
- "18"
3231
- "20"
3332
- "22"
3433
- "24"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ I've been adding load tests to the unit tests in various places. Generally speak
5151

5252
We run GitHUB CI on the following:
5353

54-
- nodejs versions 18, 20, 22, and 24
54+
- nodejs versions 20, 22, and 24
5555

5656
**Development:**
5757

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/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/empty-req-url.test.ts

Lines changed: 4 additions & 3 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
describe("test empty req.url", () => {
78
let port: number, server: http.Server;
@@ -27,7 +28,7 @@ describe("test empty req.url", () => {
2728
res.end("Something went wrong.");
2829
});
2930
httpServer = http.createServer((req, res) => {
30-
req.url = '' + new URL(`http://example.com${req.url}`).search;
31+
req.url = "" + new URL(`http://example.com${req.url}`).search;
3132
proxy.web(req, res, { target: `http://localhost:${port}/test` });
3233
});
3334

@@ -41,8 +42,8 @@ describe("test empty req.url", () => {
4142

4243
it("get using the proxy", async () => {
4344
expect(await getProxy("")).toBe("Test Page!: {}");
44-
expect(await getProxy("?foo")).toBe("Test Page!: {\"foo\":\"\"}");
45-
expect(await getProxy("?foo=bar")).toBe("Test Page!: {\"foo\":\"bar\"}");
45+
expect(await getProxy("?foo")).toBe('Test Page!: {"foo":""}');
46+
expect(await getProxy("?foo=bar")).toBe('Test Page!: {"foo":"bar"}');
4647
});
4748

4849
it("clean up", () => {

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>;

0 commit comments

Comments
 (0)