import { Express } from 'express' ; import { createServer , Server as httpServer } from 'http' ; import * as nodeFetch from 'node-fetch' ; import Server from './Server' ; import Test from './Test' ; export { Body , BodyInit , Headers , HeadersInit as HeaderInit , HeadersInit , Request , RequestCache , RequestContext , RequestCredentials , RequestInfo , RequestInit , RequestMode , RequestRedirect , Response , ResponseInit , ResponseType , } from 'node-fetch' ; export { Test } ; export { fetch } ; param server param url param options returns export default function fetch ( server , url , init ? ) { if ( ! server || ! server . listen || ! server . address || ! server . close ) { throw new Error ( 'Expected server' ) ; } if ( ! url ) { throw new Error ( 'Expected url to fetch' ) ; } const pServer = Server . create ( server ) ; return new Test ( pServer , url , init ) ; } export type FetchFunction = ( url : string | nodeFetch . Request , init ? : nodeFetch . RequestInit | undefined ) => Test ; param server returns export function makeFetch ( target ) { const server = target && ( target as Express ) . route ? createServer ( target as Express ) : ( target as httpServer ) ; if ( ! server || ! server . listen || ! server . address || ! server . close ) { throw new Error ( 'Expected server' ) ; } return function fetch ( url , init ? ) { const pServer = Server . create ( server ) ; return new Test ( pServer , url , init ) ; } ; }