undici 7.3.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/docs/docs/api/Dispatcher.md +1 -1
- package/docs/docs/api/EnvHttpProxyAgent.md +0 -2
- package/docs/docs/api/Errors.md +1 -0
- package/docs/docs/api/MockAgent.md +59 -0
- package/docs/docs/api/MockCallHistory.md +197 -0
- package/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/docs/docs/best-practices/mocking-request.md +55 -1
- package/index-fetch.js +3 -0
- package/index.js +3 -0
- package/lib/cache/memory-cache-store.js +7 -1
- package/lib/cache/sqlite-cache-store.js +11 -12
- package/lib/dispatcher/client.js +1 -1
- package/lib/dispatcher/env-http-proxy-agent.js +0 -9
- package/lib/dispatcher/pool.js +15 -1
- package/lib/handler/retry-handler.js +3 -3
- package/lib/mock/mock-agent.js +59 -4
- package/lib/mock/mock-call-history.js +248 -0
- package/lib/mock/mock-symbols.js +6 -1
- package/lib/mock/mock-utils.js +11 -3
- package/lib/util/cache.js +9 -8
- package/lib/web/fetch/body.js +1 -1
- package/lib/web/fetch/request.js +12 -9
- package/package.json +1 -1
- package/types/cache-interceptor.d.ts +2 -2
- package/types/client.d.ts +1 -1
- package/types/index.d.ts +4 -1
- package/types/mock-agent.d.ts +12 -0
- package/types/mock-call-history.d.ts +111 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import Dispatcher from './dispatcher'
|
|
2
|
+
|
|
3
|
+
declare namespace MockCallHistoryLog {
|
|
4
|
+
/** request's configuration properties */
|
|
5
|
+
export type MockCallHistoryLogProperties = 'protocol' | 'host' | 'port' | 'origin' | 'path' | 'hash' | 'fullUrl' | 'method' | 'searchParams' | 'body' | 'headers'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** a log reflecting request configuration */
|
|
9
|
+
declare class MockCallHistoryLog {
|
|
10
|
+
constructor (requestInit: Dispatcher.DispatchOptions)
|
|
11
|
+
/** protocol used. ie. 'https:' or 'http:' etc... */
|
|
12
|
+
protocol: string
|
|
13
|
+
/** request's host. */
|
|
14
|
+
host: string
|
|
15
|
+
/** request's port. */
|
|
16
|
+
port: string
|
|
17
|
+
/** request's origin. ie. https://localhost:3000. */
|
|
18
|
+
origin: string
|
|
19
|
+
/** path. never contains searchParams. */
|
|
20
|
+
path: string
|
|
21
|
+
/** request's hash. */
|
|
22
|
+
hash: string
|
|
23
|
+
/** the full url requested. */
|
|
24
|
+
fullUrl: string
|
|
25
|
+
/** request's method. */
|
|
26
|
+
method: string
|
|
27
|
+
/** search params. */
|
|
28
|
+
searchParams: Record<string, string>
|
|
29
|
+
/** request's body */
|
|
30
|
+
body: string | null | undefined
|
|
31
|
+
/** request's headers */
|
|
32
|
+
headers: Record<string, string | string[]> | null | undefined
|
|
33
|
+
|
|
34
|
+
/** returns an Map of property / value pair */
|
|
35
|
+
toMap (): Map<MockCallHistoryLog.MockCallHistoryLogProperties, string | Record<string, string | string[]> | null | undefined>
|
|
36
|
+
|
|
37
|
+
/** returns a string computed with all key value pair */
|
|
38
|
+
toString (): string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare namespace MockCallHistory {
|
|
42
|
+
export type FilterCallsOperator = 'AND' | 'OR'
|
|
43
|
+
|
|
44
|
+
/** modify the filtering behavior */
|
|
45
|
+
export interface FilterCallsOptions {
|
|
46
|
+
/** the operator to apply when filtering. 'OR' will adds any MockCallHistoryLog matching any criteria given. 'AND' will adds only MockCallHistoryLog matching every criteria given. (default 'OR') */
|
|
47
|
+
operator?: FilterCallsOperator | Lowercase<FilterCallsOperator>
|
|
48
|
+
}
|
|
49
|
+
/** a function to be executed for filtering MockCallHistoryLog */
|
|
50
|
+
export type FilterCallsFunctionCriteria = (log: MockCallHistoryLog) => boolean
|
|
51
|
+
|
|
52
|
+
/** parameter to filter MockCallHistoryLog */
|
|
53
|
+
export type FilterCallsParameter = string | RegExp | undefined | null
|
|
54
|
+
|
|
55
|
+
/** an object to execute multiple filtering at once */
|
|
56
|
+
export interface FilterCallsObjectCriteria extends Record<string, FilterCallsParameter> {
|
|
57
|
+
/** filter by request protocol. ie https: */
|
|
58
|
+
protocol?: FilterCallsParameter;
|
|
59
|
+
/** filter by request host. */
|
|
60
|
+
host?: FilterCallsParameter;
|
|
61
|
+
/** filter by request port. */
|
|
62
|
+
port?: FilterCallsParameter;
|
|
63
|
+
/** filter by request origin. */
|
|
64
|
+
origin?: FilterCallsParameter;
|
|
65
|
+
/** filter by request path. */
|
|
66
|
+
path?: FilterCallsParameter;
|
|
67
|
+
/** filter by request hash. */
|
|
68
|
+
hash?: FilterCallsParameter;
|
|
69
|
+
/** filter by request fullUrl. */
|
|
70
|
+
fullUrl?: FilterCallsParameter;
|
|
71
|
+
/** filter by request method. */
|
|
72
|
+
method?: FilterCallsParameter;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** a call history to track requests configuration */
|
|
77
|
+
declare class MockCallHistory {
|
|
78
|
+
constructor (name: string)
|
|
79
|
+
/** returns an array of MockCallHistoryLog. */
|
|
80
|
+
calls (): Array<MockCallHistoryLog>
|
|
81
|
+
/** returns the first MockCallHistoryLog */
|
|
82
|
+
firstCall (): MockCallHistoryLog | undefined
|
|
83
|
+
/** returns the last MockCallHistoryLog. */
|
|
84
|
+
lastCall (): MockCallHistoryLog | undefined
|
|
85
|
+
/** returns the nth MockCallHistoryLog. */
|
|
86
|
+
nthCall (position: number): MockCallHistoryLog | undefined
|
|
87
|
+
/** return all MockCallHistoryLog matching any of criteria given. if an object is used with multiple properties, you can change the operator to apply during filtering on options */
|
|
88
|
+
filterCalls (criteria: MockCallHistory.FilterCallsFunctionCriteria | MockCallHistory.FilterCallsObjectCriteria | RegExp, options?: MockCallHistory.FilterCallsOptions): Array<MockCallHistoryLog>
|
|
89
|
+
/** return all MockCallHistoryLog matching the given protocol. if a string is given, it is matched with includes */
|
|
90
|
+
filterCallsByProtocol (protocol: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
91
|
+
/** return all MockCallHistoryLog matching the given host. if a string is given, it is matched with includes */
|
|
92
|
+
filterCallsByHost (host: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
93
|
+
/** return all MockCallHistoryLog matching the given port. if a string is given, it is matched with includes */
|
|
94
|
+
filterCallsByPort (port: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
95
|
+
/** return all MockCallHistoryLog matching the given origin. if a string is given, it is matched with includes */
|
|
96
|
+
filterCallsByOrigin (origin: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
97
|
+
/** return all MockCallHistoryLog matching the given path. if a string is given, it is matched with includes */
|
|
98
|
+
filterCallsByPath (path: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
99
|
+
/** return all MockCallHistoryLog matching the given hash. if a string is given, it is matched with includes */
|
|
100
|
+
filterCallsByHash (hash: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
101
|
+
/** return all MockCallHistoryLog matching the given fullUrl. if a string is given, it is matched with includes */
|
|
102
|
+
filterCallsByFullUrl (fullUrl: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
103
|
+
/** return all MockCallHistoryLog matching the given method. if a string is given, it is matched with includes */
|
|
104
|
+
filterCallsByMethod (method: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
105
|
+
/** clear all MockCallHistoryLog on this MockCallHistory. */
|
|
106
|
+
clear (): void
|
|
107
|
+
/** use it with for..of loop or spread operator */
|
|
108
|
+
[Symbol.iterator]: () => Generator<MockCallHistoryLog>
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { MockCallHistoryLog, MockCallHistory }
|