Skip to content

Commit c4fd429

Browse files
committed
move stuff to types
1 parent d3ff204 commit c4fd429

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

mod.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { assertEquals, assertMatch, parseMediaType } from './deps.ts'
2-
import { Handler, HandlerOrListener } from './types.ts'
2+
import type {
3+
FetchFunction,
4+
Handler,
5+
HandlerOrListener,
6+
MakeFetchResponse,
7+
} from './types.ts'
38

49
// credit - 'https://deno.land/x/free_port@v1.2.0/mod.ts'
510
function random(min: number, max: number): number {
@@ -22,15 +27,6 @@ const getFreeListener = (
2227
throw new Error('Unable to get free port')
2328
}
2429

25-
type Expect = {
26-
expectStatus: (a: number, b?: string) => Expect
27-
expectHeader: (a: string, b: string | RegExp | null | string[]) => Expect
28-
expectBody: (a: unknown) => void
29-
expect: (a: unknown, b?: unknown) => Expect
30-
}
31-
32-
type MakeFetchResponse = { port: number } & Response & Expect
33-
3430
const fetchEndpoint = async (
3531
port: number,
3632
url: string | URL,
@@ -97,7 +93,7 @@ const makeFetchPromise = (handlerOrListener: HandlerOrListener) => {
9793
}
9894
}
9995

100-
export const makeFetch = (h: HandlerOrListener) => {
96+
export const makeFetch = (h: HandlerOrListener): FetchFunction => {
10197
const { resp, port } = makeFetchPromise(h)
10298
async function fetch(url: string | URL, options?: RequestInit) {
10399
const { res, data } = await resp(url, options)

types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@ export type Handler = (
44
) => Response | Promise<Response>
55

66
export type HandlerOrListener = Handler | Deno.Listener
7+
8+
export type MakeFetchResponse = { port: number } & Response & Expect
9+
10+
export type FetchFunction = (
11+
url: string | URL,
12+
options?: RequestInit,
13+
) => Promise<MakeFetchResponse>
14+
15+
export type Expect = {
16+
expectStatus: (a: number, b?: string) => Expect
17+
expectHeader: (a: string, b: string | RegExp | null | string[]) => Expect
18+
expectBody: (a: unknown) => void
19+
expect: (a: unknown, b?: unknown) => Expect
20+
}

0 commit comments

Comments
 (0)