deno.land / x / oauth4webapi@v1.2.2 / test / _setup.ts

_setup.ts
View Documentation
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { ExecutionContext } from 'ava'import * as undici from 'undici'import { Readable } from 'node:stream'
import type { AuthorizationServer, Client } from '../src/index.js'
export interface Context { mock: undici.MockAgent intercept: InstanceType<typeof undici.MockPool>['intercept']}
export default (t: ExecutionContext<Context>) => { const mockAgent = new undici.MockAgent() mockAgent.disableNetConnect() undici.setGlobalDispatcher(mockAgent) const pool = mockAgent.get(identifier)
t.context.mock ||= mockAgent t.context.intercept ||= undici.MockPool.prototype.intercept.bind(pool)}
export async function teardown(t: ExecutionContext<Context>) { t.context.mock.assertNoPendingInterceptors() await t.context.mock.close()}
const identifier = 'https://op.example.com'
export function endpoint(pathname: string, base = identifier) { return new URL(pathname, base).href}
export const issuer = <AuthorizationServer>{ issuer: identifier,}
export const client = <Client>{ client_id: 'urn:example:client_id',}
export function getResponse( body: string, { status = 200, headers = new Headers() } = {},): Response { let bodyInit: BodyInit if (process.version.startsWith('v16')) { bodyInit = Buffer.from(body) } else { bodyInit = Readable.toWeb(Readable.from(Buffer.from(body))) } return new Response(bodyInit, { status, headers })}
export const UA = /^oauth4webapi\/v\d+\.\d+\.\d+$/
oauth4webapi

Version Info

Tagged at
2 years ago