-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathutils.ts
More file actions
34 lines (31 loc) · 910 Bytes
/
utils.ts
File metadata and controls
34 lines (31 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { TestServer } from '@logux/server'
import type { Requester } from '@slowreader/api'
import { equal } from 'node:assert'
export { buildTestServer, cleanAllTables } from '../test.ts'
export async function testRequest<
Params extends Record<string, unknown>,
ResponseJSON
>(
server: TestServer,
requester: Requester<Params, ResponseJSON>,
params: Params,
responseProcessor?: (response: Response) => void
): Promise<ResponseJSON> {
let response = await requester(params, { fetch: server.fetch })
if (!response.ok) throw new Error(await response.text())
if (responseProcessor) responseProcessor(response)
return response.json()
}
export async function throws(
cb: () => Promise<unknown>,
msg: string
): Promise<Error | undefined> {
let error: Error | undefined
try {
await cb()
} catch (e) {
error = e as Error
}
equal(error?.message, msg)
return error
}