File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import * as undici from 'undici'
22import * as lib from '../src/index.js'
33
4+ // Test facade for the public API. Importing this module instead of ../src/index.js keeps the tests
5+ // using the normal oauth4webapi call signatures while forcing every HTTP request through undici.
46export * from '../src/index.js'
57
8+ // Request helpers return the Response object created by undici.fetch. Export the matching
9+ // constructor so tests can assert against the implementation they intentionally exercise.
610export const Response = undici . Response as unknown as typeof globalThis . Response
711
12+ // The runtime value is undici's Response. The cast is only a TypeScript boundary because undici's
13+ // Response type and the DOM Response type differ structurally.
814const customFetch : NonNullable < lib . HttpRequestOptions < string , unknown > [ typeof lib . customFetch ] > = (
915 url ,
1016 options ,
@@ -19,6 +25,8 @@ function withCustomFetch<T extends object | undefined>(options: T): T & Options
1925 } as T & Options
2026}
2127
28+ // The public functions put their optional request options at different argument positions.
29+ // Wrapping them here keeps individual tests from repeating [customFetch]: undici.fetch.
2230function defaultCustomFetch < Fn extends ( ...args : any [ ] ) => any > ( fn : Fn , optionsIndex : number ) : Fn {
2331 return ( ( ...args : Parameters < Fn > ) : ReturnType < Fn > => {
2432 args [ optionsIndex ] = withCustomFetch ( args [ optionsIndex ] as object | undefined )
You can’t perform that action at this time.
0 commit comments