-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3ff204
commit c4fd429
Showing
2 changed files
with
21 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { assertEquals, assertMatch, parseMediaType } from './deps.ts' | ||
import { Handler, HandlerOrListener } from './types.ts' | ||
import type { | ||
FetchFunction, | ||
Handler, | ||
HandlerOrListener, | ||
MakeFetchResponse, | ||
} from './types.ts' | ||
|
||
// credit - 'https://deno.land/x/[email protected]/mod.ts' | ||
function random(min: number, max: number): number { | ||
|
@@ -22,15 +27,6 @@ const getFreeListener = ( | |
throw new Error('Unable to get free port') | ||
} | ||
|
||
type Expect = { | ||
expectStatus: (a: number, b?: string) => Expect | ||
expectHeader: (a: string, b: string | RegExp | null | string[]) => Expect | ||
expectBody: (a: unknown) => void | ||
expect: (a: unknown, b?: unknown) => Expect | ||
} | ||
|
||
type MakeFetchResponse = { port: number } & Response & Expect | ||
|
||
const fetchEndpoint = async ( | ||
port: number, | ||
url: string | URL, | ||
|
@@ -97,7 +93,7 @@ const makeFetchPromise = (handlerOrListener: HandlerOrListener) => { | |
} | ||
} | ||
|
||
export const makeFetch = (h: HandlerOrListener) => { | ||
export const makeFetch = (h: HandlerOrListener): FetchFunction => { | ||
const { resp, port } = makeFetchPromise(h) | ||
async function fetch(url: string | URL, options?: RequestInit) { | ||
const { res, data } = await resp(url, options) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters