Skip to content

Commit

Permalink
Convert mocha tests to jest for all packages (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed May 4, 2023
1 parent 4333067 commit c169ced
Show file tree
Hide file tree
Showing 55 changed files with 1,492 additions and 3,158 deletions.
15 changes: 15 additions & 0 deletions .changeset/big-feet-beam.md
@@ -0,0 +1,15 @@
---
'data-uri-to-buffer': patch
'https-proxy-agent': patch
'socks-proxy-agent': patch
'http-proxy-agent': patch
'pac-proxy-agent': patch
'pac-resolver': patch
'degenerator': patch
'proxy-agent': patch
'agent-base': patch
'get-uri': patch
'proxy': patch
---

Convert mocha tests to jest for all packages
3 changes: 1 addition & 2 deletions packages/agent-base/package.json
Expand Up @@ -11,8 +11,7 @@
"build": "tsc",
"test": "jest --env node --verbose --bail",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
"pack": "node ../../scripts/pack.mjs"
},
"repository": {
"type": "git",
Expand Down
15 changes: 11 additions & 4 deletions packages/agent-base/src/helpers.ts
Expand Up @@ -2,6 +2,10 @@ import * as http from 'http';
import * as https from 'https';
import type { Readable } from 'stream';

export type ThenableRequest = http.ClientRequest & {
then: Promise<http.IncomingMessage>['then'];
};

export async function toBuffer(stream: Readable): Promise<Buffer> {
let length = 0;
const chunks: Buffer[] = [];
Expand All @@ -28,12 +32,15 @@ export async function json(stream: Readable): Promise<any> {
export function req(
url: string | URL,
opts: https.RequestOptions = {}
): Promise<http.IncomingMessage> {
return new Promise((resolve, reject) => {
): ThenableRequest {
let req!: ThenableRequest;
const promise = new Promise<http.IncomingMessage>((resolve, reject) => {
const href = typeof url === 'string' ? url : url.href;
(href.startsWith('https:') ? https : http)
req = (href.startsWith('https:') ? https : http)
.request(url, opts, resolve)
.once('error', reject)
.end();
.end() as ThenableRequest;
});
req.then = promise.then.bind(promise);
return req;
}

1 comment on commit c169ced

@vercel
Copy link

@vercel vercel bot commented on c169ced May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

proxy-agents – ./

proxy-agents-git-main-tootallnate.vercel.app
proxy-agents.vercel.app
proxy-agents-tootallnate.vercel.app

Please sign in to comment.