Skip to content

Commit aeb9256

Browse files
authored
ci: migrate from jest to vitest (#1180)
1 parent 2dd8d71 commit aeb9256

40 files changed

Lines changed: 755 additions & 2184 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ jobs:
153153
run: yarn install --frozen-lockfile --ignore-scripts
154154

155155
- name: yarn test
156-
run: yarn test --ci --reporters="default" --reporters="github-actions"
156+
run: yarn test
157+
158+
- name: yarn test:types
159+
run: yarn test:types
157160

158161
env:
159162
CI: true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ $ yarn build
623623
$ yarn test
624624

625625
# code coverage
626-
$ yarn cover
626+
$ yarn coverage
627627

628628
# check spelling mistakes
629629
$ yarn spellcheck

jest.config.js

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

jest.setup.js

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

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
1919
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
2020
"build": "tsc --build",
21-
"test": "jest",
22-
"coverage": "jest --coverage",
21+
"test": "vitest run",
22+
"test:types": "tsc --project tsconfig.test.json --noEmit",
23+
"coverage": "vitest run --coverage",
2324
"prepare": "husky && patch-package",
2425
"prepack": "yarn clean && yarn test && yarn build",
2526
"spellcheck": "npx --yes cspell --show-context --show-suggestions '**/*.*'"
@@ -64,28 +65,27 @@
6465
"@types/eslint": "9.6.1",
6566
"@types/express": "5.0.6",
6667
"@types/is-glob": "4.0.4",
67-
"@types/jest": "30.0.0",
6868
"@types/micromatch": "4.0.10",
6969
"@types/node": "24.10.2",
7070
"@types/supertest": "7.2.0",
7171
"@types/ws": "8.18.1",
72+
"@vitest/coverage-v8": "^4.1.2",
7273
"body-parser": "2.2.2",
7374
"eslint": "10.0.2",
7475
"express": "5.2.1",
7576
"get-port": "5.1.1",
7677
"globals": "17.3.0",
7778
"husky": "9.1.7",
78-
"jest": "30.2.0",
7979
"lint-staged": "16.3.0",
8080
"mockttp": "4.2.1",
8181
"open": "8.4.2",
8282
"patch-package": "8.0.1",
8383
"pkg-pr-new": "0.0.65",
8484
"prettier": "3.8.1",
8585
"supertest": "7.2.2",
86-
"ts-jest": "29.4.6",
8786
"typescript": "5.9.3",
8887
"typescript-eslint": "8.56.1",
88+
"vitest": "^4.1.2",
8989
"ws": "8.19.0"
9090
},
9191
"dependencies": {

src/configuration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import type * as http from 'node:http';
2+
13
import { ERRORS } from './errors';
24
import { Options } from './types';
35

4-
export function verifyConfig<TReq, TRes>(options: Options<TReq, TRes>): void {
6+
export function verifyConfig<TReq extends http.IncomingMessage, TRes extends http.ServerResponse>(
7+
options: Options<TReq, TRes>,
8+
): void {
59
if (!options.target && !options.router) {
610
throw new Error(ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);
711
}

src/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as createDebug from 'debug';
1+
import createDebug from 'debug';
22

33
/**
44
* Debug instance with the given namespace: http-proxy-middleware

src/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { HttpProxyMiddleware } from './http-proxy-middleware';
44
import type { NextFunction, Options, RequestHandler } from './types';
55

66
export function createProxyMiddleware<
7-
TReq = http.IncomingMessage,
8-
TRes = http.ServerResponse,
7+
TReq extends http.IncomingMessage = http.IncomingMessage,
8+
TRes extends http.ServerResponse = http.ServerResponse,
99
TNext = NextFunction,
1010
>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext> {
1111
const { middleware } = new HttpProxyMiddleware<TReq, TRes>(options);

src/get-plugins.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type * as http from 'node:http';
2+
13
import {
24
debugProxyErrorsPlugin,
35
errorResponsePlugin,
@@ -6,7 +8,9 @@ import {
68
} from './plugins/default';
79
import type { Options, Plugin } from './types';
810

9-
export function getPlugins<TReq, TRes>(options: Options<TReq, TRes>): Plugin<TReq, TRes>[] {
11+
export function getPlugins<TReq extends http.IncomingMessage, TRes extends http.ServerResponse>(
12+
options: Options<TReq, TRes>,
13+
): Plugin<TReq, TRes>[] {
1014
// don't load default errorResponsePlugin if user has specified their own
1115
const maybeErrorResponsePlugin = options.on?.error ? [] : [errorResponsePlugin];
1216

src/http-proxy-middleware.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import * as Router from './router';
1414
import type { Filter, Logger, Options, RequestHandler } from './types';
1515
import { getFunctionName } from './utils/function';
1616

17-
export class HttpProxyMiddleware<TReq, TRes> {
17+
export class HttpProxyMiddleware<
18+
TReq extends http.IncomingMessage = http.IncomingMessage,
19+
TRes extends http.ServerResponse = http.ServerResponse,
20+
> {
1821
private wsInternalSubscribed = false;
1922
private serverOnCloseSubscribed = false;
2023
private proxyOptions: Options<TReq, TRes>;
@@ -44,7 +47,11 @@ export class HttpProxyMiddleware<TReq, TRes> {
4447
}
4548

4649
// https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this
47-
public middleware: RequestHandler = (async (req, res, next?) => {
50+
public middleware: RequestHandler<TReq, TRes> = (async (
51+
req: TReq,
52+
res: TRes,
53+
next?: (err?: unknown) => void,
54+
) => {
4855
if (this.shouldProxy(this.proxyOptions.pathFilter, req)) {
4956
let activeProxyOptions: Options<TReq, TRes>;
5057
try {

0 commit comments

Comments
 (0)