Skip to content

Commit 38c75cd

Browse files
committed
test: document _lib.ts
1 parent b7139b3 commit 38c75cd

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test/_lib.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import * as undici from 'undici'
22
import * 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.
46
export * 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.
610
export 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.
814
const 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.
2230
function 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)

0 commit comments

Comments
 (0)