msw-fetch-mock 0.3.3 → 0.4.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 +46 -15
- package/README.zh-TW.md +274 -0
- package/dist/browser.cjs +5 -4
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +2 -1
- package/dist/{chunk-OSKJXLRH.cjs → chunk-27BEAYUI.cjs} +4 -4
- package/dist/chunk-3RE2WWHX.cjs +1 -0
- package/dist/{chunk-3RAWYKAG.js → chunk-3XFP4NAO.js} +30 -0
- package/dist/chunk-GZFGTCZB.js +0 -0
- package/dist/{chunk-NFPFLI3N.js → chunk-IWHL7QPE.js} +1 -1
- package/dist/{chunk-N6B7UP6B.cjs → chunk-VUNESK75.cjs} +30 -0
- package/dist/{fetch-mock-DhiqmHdF.d.cts → fetch-mock-1oOS8WUJ.d.cts} +31 -1
- package/dist/{fetch-mock-DhiqmHdF.d.ts → fetch-mock-1oOS8WUJ.d.ts} +31 -1
- package/dist/index.cjs +4 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/legacy.cjs +5 -5
- package/dist/legacy.d.cts +2 -2
- package/dist/legacy.d.ts +2 -2
- package/dist/legacy.js +1 -1
- package/dist/native.cjs +92 -0
- package/dist/native.d.cts +20 -0
- package/dist/native.d.ts +20 -0
- package/dist/native.js +92 -0
- package/dist/node.cjs +4 -3
- package/dist/node.d.cts +14 -2
- package/dist/node.d.ts +14 -2
- package/dist/node.js +3 -2
- package/docs/api.md +35 -10
- package/docs/api.zh-TW.md +707 -0
- package/docs/cloudflare-migration.zh-TW.md +80 -0
- package/docs/msw-v1-legacy.zh-TW.md +94 -0
- package/package.json +15 -1
|
@@ -28,6 +28,10 @@ var MockCallHistoryLog = class {
|
|
|
28
28
|
if (this.body === null) return null;
|
|
29
29
|
return JSON.parse(this.body);
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns a Map representation of this call log.
|
|
33
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
34
|
+
*/
|
|
31
35
|
toMap() {
|
|
32
36
|
return /* @__PURE__ */ new Map([
|
|
33
37
|
["body", this.body],
|
|
@@ -43,6 +47,10 @@ var MockCallHistoryLog = class {
|
|
|
43
47
|
["hash", this.hash]
|
|
44
48
|
]);
|
|
45
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns a pipe-separated string representation of this call log.
|
|
52
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
53
|
+
*/
|
|
46
54
|
toString() {
|
|
47
55
|
return [
|
|
48
56
|
`method->${this.method}`,
|
|
@@ -105,32 +113,47 @@ var MockCallHistory = (_class = class {constructor() { _class.prototype.__init.c
|
|
|
105
113
|
(log) => operator === "AND" ? predicates.every((p) => p(log)) : predicates.some((p) => p(log))
|
|
106
114
|
);
|
|
107
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Filter helper — matches a single field by exact string or RegExp.
|
|
118
|
+
*
|
|
119
|
+
* The `filterCallsByXxx` methods below mirror the `cloudflare:test` fetchMock
|
|
120
|
+
* API so that tests written for Cloudflare Workers can be reused with this library
|
|
121
|
+
* without modification.
|
|
122
|
+
*/
|
|
108
123
|
filterBy(field, filter) {
|
|
109
124
|
return this.logs.filter(
|
|
110
125
|
(log) => typeof filter === "string" ? log[field] === filter : filter.test(String(log[field]))
|
|
111
126
|
);
|
|
112
127
|
}
|
|
128
|
+
/** Filter calls by HTTP method. Mirrors `cloudflare:test` fetchMock API. */
|
|
113
129
|
filterCallsByMethod(filter) {
|
|
114
130
|
return this.filterBy("method", filter);
|
|
115
131
|
}
|
|
132
|
+
/** Filter calls by path. Mirrors `cloudflare:test` fetchMock API. */
|
|
116
133
|
filterCallsByPath(filter) {
|
|
117
134
|
return this.filterBy("path", filter);
|
|
118
135
|
}
|
|
136
|
+
/** Filter calls by origin. Mirrors `cloudflare:test` fetchMock API. */
|
|
119
137
|
filterCallsByOrigin(filter) {
|
|
120
138
|
return this.filterBy("origin", filter);
|
|
121
139
|
}
|
|
140
|
+
/** Filter calls by protocol. Mirrors `cloudflare:test` fetchMock API. */
|
|
122
141
|
filterCallsByProtocol(filter) {
|
|
123
142
|
return this.filterBy("protocol", filter);
|
|
124
143
|
}
|
|
144
|
+
/** Filter calls by host. Mirrors `cloudflare:test` fetchMock API. */
|
|
125
145
|
filterCallsByHost(filter) {
|
|
126
146
|
return this.filterBy("host", filter);
|
|
127
147
|
}
|
|
148
|
+
/** Filter calls by port. Mirrors `cloudflare:test` fetchMock API. */
|
|
128
149
|
filterCallsByPort(filter) {
|
|
129
150
|
return this.filterBy("port", filter);
|
|
130
151
|
}
|
|
152
|
+
/** Filter calls by URL hash. Mirrors `cloudflare:test` fetchMock API. */
|
|
131
153
|
filterCallsByHash(filter) {
|
|
132
154
|
return this.filterBy("hash", filter);
|
|
133
155
|
}
|
|
156
|
+
/** Filter calls by full URL. Mirrors `cloudflare:test` fetchMock API. */
|
|
134
157
|
filterCallsByFullUrl(filter) {
|
|
135
158
|
return this.filterBy("fullUrl", filter);
|
|
136
159
|
}
|
|
@@ -327,12 +350,19 @@ var FetchMock = (_class2 = class _FetchMock {
|
|
|
327
350
|
const activeHandlers = [...this.mswHandlers.entries()].filter(([p]) => !p.consumed || p.persist).map(([, handler]) => handler);
|
|
328
351
|
this.adapter.resetHandlers(...activeHandlers);
|
|
329
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Returns the call history instance.
|
|
355
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
356
|
+
* Equivalent to the `calls` getter.
|
|
357
|
+
*/
|
|
330
358
|
getCallHistory() {
|
|
331
359
|
return this._calls;
|
|
332
360
|
}
|
|
361
|
+
/** Clears recorded call history. Mirrors `cloudflare:test` fetchMock API. */
|
|
333
362
|
clearCallHistory() {
|
|
334
363
|
this._calls.clear();
|
|
335
364
|
}
|
|
365
|
+
/** Alias for `clearCallHistory()`. Mirrors `cloudflare:test` fetchMock API. */
|
|
336
366
|
clearAllCallHistory() {
|
|
337
367
|
this.clearCallHistory();
|
|
338
368
|
}
|
|
@@ -25,7 +25,15 @@ declare class MockCallHistoryLog {
|
|
|
25
25
|
readonly hash: string;
|
|
26
26
|
constructor(data: MockCallHistoryLogData);
|
|
27
27
|
json(): unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a Map representation of this call log.
|
|
30
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
31
|
+
*/
|
|
28
32
|
toMap(): Map<string, string | null | Record<string, string>>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a pipe-separated string representation of this call log.
|
|
35
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
36
|
+
*/
|
|
29
37
|
toString(): string;
|
|
30
38
|
}
|
|
31
39
|
interface CallHistoryFilterCriteria {
|
|
@@ -52,14 +60,29 @@ declare class MockCallHistory {
|
|
|
52
60
|
filterCalls(criteria: ((log: MockCallHistoryLog) => boolean) | CallHistoryFilterCriteria | RegExp, options?: {
|
|
53
61
|
operator?: 'AND' | 'OR';
|
|
54
62
|
}): MockCallHistoryLog[];
|
|
63
|
+
/**
|
|
64
|
+
* Filter helper — matches a single field by exact string or RegExp.
|
|
65
|
+
*
|
|
66
|
+
* The `filterCallsByXxx` methods below mirror the `cloudflare:test` fetchMock
|
|
67
|
+
* API so that tests written for Cloudflare Workers can be reused with this library
|
|
68
|
+
* without modification.
|
|
69
|
+
*/
|
|
55
70
|
private filterBy;
|
|
71
|
+
/** Filter calls by HTTP method. Mirrors `cloudflare:test` fetchMock API. */
|
|
56
72
|
filterCallsByMethod(filter: string | RegExp): MockCallHistoryLog[];
|
|
73
|
+
/** Filter calls by path. Mirrors `cloudflare:test` fetchMock API. */
|
|
57
74
|
filterCallsByPath(filter: string | RegExp): MockCallHistoryLog[];
|
|
75
|
+
/** Filter calls by origin. Mirrors `cloudflare:test` fetchMock API. */
|
|
58
76
|
filterCallsByOrigin(filter: string | RegExp): MockCallHistoryLog[];
|
|
77
|
+
/** Filter calls by protocol. Mirrors `cloudflare:test` fetchMock API. */
|
|
59
78
|
filterCallsByProtocol(filter: string | RegExp): MockCallHistoryLog[];
|
|
79
|
+
/** Filter calls by host. Mirrors `cloudflare:test` fetchMock API. */
|
|
60
80
|
filterCallsByHost(filter: string | RegExp): MockCallHistoryLog[];
|
|
81
|
+
/** Filter calls by port. Mirrors `cloudflare:test` fetchMock API. */
|
|
61
82
|
filterCallsByPort(filter: string | RegExp): MockCallHistoryLog[];
|
|
83
|
+
/** Filter calls by URL hash. Mirrors `cloudflare:test` fetchMock API. */
|
|
62
84
|
filterCallsByHash(filter: string | RegExp): MockCallHistoryLog[];
|
|
85
|
+
/** Filter calls by full URL. Mirrors `cloudflare:test` fetchMock API. */
|
|
63
86
|
filterCallsByFullUrl(filter: string | RegExp): MockCallHistoryLog[];
|
|
64
87
|
}
|
|
65
88
|
|
|
@@ -177,8 +200,15 @@ declare class FetchMock {
|
|
|
177
200
|
* go through MSW's onUnhandledRequest instead of silently passing through.
|
|
178
201
|
*/
|
|
179
202
|
private syncMswHandlers;
|
|
203
|
+
/**
|
|
204
|
+
* Returns the call history instance.
|
|
205
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
206
|
+
* Equivalent to the `calls` getter.
|
|
207
|
+
*/
|
|
180
208
|
getCallHistory(): MockCallHistory;
|
|
209
|
+
/** Clears recorded call history. Mirrors `cloudflare:test` fetchMock API. */
|
|
181
210
|
clearCallHistory(): void;
|
|
211
|
+
/** Alias for `clearCallHistory()`. Mirrors `cloudflare:test` fetchMock API. */
|
|
182
212
|
clearAllCallHistory(): void;
|
|
183
213
|
defaultReplyHeaders(headers: Record<string, string>): void;
|
|
184
214
|
enableCallHistory(): void;
|
|
@@ -196,4 +226,4 @@ declare class FetchMock {
|
|
|
196
226
|
get(origin: string | RegExp | ((origin: string) => boolean)): MockPool;
|
|
197
227
|
}
|
|
198
228
|
|
|
199
|
-
export { type ActivateOptions as A, type CallHistoryFilterCriteria as C, FetchMock as F, type HandlerFactory as H, type InterceptOptions as I, type MswAdapter as M, type OnUnhandledRequest as O, type PendingInterceptor as P, type ResolvedActivateOptions as R, type SetupWorkerLike as S, MockCallHistory as a, MockCallHistoryLog as b, type MockCallHistoryLogData as c, type MockInterceptor as d, type MockPool as e, type MockReplyChain as f, type
|
|
229
|
+
export { type ActivateOptions as A, type CallHistoryFilterCriteria as C, FetchMock as F, type HandlerFactory as H, type InterceptOptions as I, type MswAdapter as M, type OnUnhandledRequest as O, type PendingInterceptor as P, type ResolvedActivateOptions as R, type SetupWorkerLike as S, MockCallHistory as a, MockCallHistoryLog as b, type MockCallHistoryLogData as c, type MockInterceptor as d, type MockPool as e, type MockReplyChain as f, type ReplyCallback as g, type ReplyOptions as h, type SingleReplyCallback as i, type SingleReplyResult as j, type HttpMethod as k, type SetupServerLike as l };
|
|
@@ -25,7 +25,15 @@ declare class MockCallHistoryLog {
|
|
|
25
25
|
readonly hash: string;
|
|
26
26
|
constructor(data: MockCallHistoryLogData);
|
|
27
27
|
json(): unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a Map representation of this call log.
|
|
30
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
31
|
+
*/
|
|
28
32
|
toMap(): Map<string, string | null | Record<string, string>>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a pipe-separated string representation of this call log.
|
|
35
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
36
|
+
*/
|
|
29
37
|
toString(): string;
|
|
30
38
|
}
|
|
31
39
|
interface CallHistoryFilterCriteria {
|
|
@@ -52,14 +60,29 @@ declare class MockCallHistory {
|
|
|
52
60
|
filterCalls(criteria: ((log: MockCallHistoryLog) => boolean) | CallHistoryFilterCriteria | RegExp, options?: {
|
|
53
61
|
operator?: 'AND' | 'OR';
|
|
54
62
|
}): MockCallHistoryLog[];
|
|
63
|
+
/**
|
|
64
|
+
* Filter helper — matches a single field by exact string or RegExp.
|
|
65
|
+
*
|
|
66
|
+
* The `filterCallsByXxx` methods below mirror the `cloudflare:test` fetchMock
|
|
67
|
+
* API so that tests written for Cloudflare Workers can be reused with this library
|
|
68
|
+
* without modification.
|
|
69
|
+
*/
|
|
55
70
|
private filterBy;
|
|
71
|
+
/** Filter calls by HTTP method. Mirrors `cloudflare:test` fetchMock API. */
|
|
56
72
|
filterCallsByMethod(filter: string | RegExp): MockCallHistoryLog[];
|
|
73
|
+
/** Filter calls by path. Mirrors `cloudflare:test` fetchMock API. */
|
|
57
74
|
filterCallsByPath(filter: string | RegExp): MockCallHistoryLog[];
|
|
75
|
+
/** Filter calls by origin. Mirrors `cloudflare:test` fetchMock API. */
|
|
58
76
|
filterCallsByOrigin(filter: string | RegExp): MockCallHistoryLog[];
|
|
77
|
+
/** Filter calls by protocol. Mirrors `cloudflare:test` fetchMock API. */
|
|
59
78
|
filterCallsByProtocol(filter: string | RegExp): MockCallHistoryLog[];
|
|
79
|
+
/** Filter calls by host. Mirrors `cloudflare:test` fetchMock API. */
|
|
60
80
|
filterCallsByHost(filter: string | RegExp): MockCallHistoryLog[];
|
|
81
|
+
/** Filter calls by port. Mirrors `cloudflare:test` fetchMock API. */
|
|
61
82
|
filterCallsByPort(filter: string | RegExp): MockCallHistoryLog[];
|
|
83
|
+
/** Filter calls by URL hash. Mirrors `cloudflare:test` fetchMock API. */
|
|
62
84
|
filterCallsByHash(filter: string | RegExp): MockCallHistoryLog[];
|
|
85
|
+
/** Filter calls by full URL. Mirrors `cloudflare:test` fetchMock API. */
|
|
63
86
|
filterCallsByFullUrl(filter: string | RegExp): MockCallHistoryLog[];
|
|
64
87
|
}
|
|
65
88
|
|
|
@@ -177,8 +200,15 @@ declare class FetchMock {
|
|
|
177
200
|
* go through MSW's onUnhandledRequest instead of silently passing through.
|
|
178
201
|
*/
|
|
179
202
|
private syncMswHandlers;
|
|
203
|
+
/**
|
|
204
|
+
* Returns the call history instance.
|
|
205
|
+
* Provided for compatibility with the `cloudflare:test` fetchMock API.
|
|
206
|
+
* Equivalent to the `calls` getter.
|
|
207
|
+
*/
|
|
180
208
|
getCallHistory(): MockCallHistory;
|
|
209
|
+
/** Clears recorded call history. Mirrors `cloudflare:test` fetchMock API. */
|
|
181
210
|
clearCallHistory(): void;
|
|
211
|
+
/** Alias for `clearCallHistory()`. Mirrors `cloudflare:test` fetchMock API. */
|
|
182
212
|
clearAllCallHistory(): void;
|
|
183
213
|
defaultReplyHeaders(headers: Record<string, string>): void;
|
|
184
214
|
enableCallHistory(): void;
|
|
@@ -196,4 +226,4 @@ declare class FetchMock {
|
|
|
196
226
|
get(origin: string | RegExp | ((origin: string) => boolean)): MockPool;
|
|
197
227
|
}
|
|
198
228
|
|
|
199
|
-
export { type ActivateOptions as A, type CallHistoryFilterCriteria as C, FetchMock as F, type HandlerFactory as H, type InterceptOptions as I, type MswAdapter as M, type OnUnhandledRequest as O, type PendingInterceptor as P, type ResolvedActivateOptions as R, type SetupWorkerLike as S, MockCallHistory as a, MockCallHistoryLog as b, type MockCallHistoryLogData as c, type MockInterceptor as d, type MockPool as e, type MockReplyChain as f, type
|
|
229
|
+
export { type ActivateOptions as A, type CallHistoryFilterCriteria as C, FetchMock as F, type HandlerFactory as H, type InterceptOptions as I, type MswAdapter as M, type OnUnhandledRequest as O, type PendingInterceptor as P, type ResolvedActivateOptions as R, type SetupWorkerLike as S, MockCallHistory as a, MockCallHistoryLog as b, type MockCallHistoryLogData as c, type MockInterceptor as d, type MockPool as e, type MockReplyChain as f, type ReplyCallback as g, type ReplyOptions as h, type SingleReplyCallback as i, type SingleReplyResult as j, type HttpMethod as k, type SetupServerLike as l };
|
package/dist/index.cjs
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk27BEAYUIcjs = require('./chunk-27BEAYUI.cjs');
|
|
6
6
|
require('./chunk-LVGXTY6J.cjs');
|
|
7
|
+
require('./chunk-3RE2WWHX.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _chunkVUNESK75cjs = require('./chunk-VUNESK75.cjs');
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
|
|
@@ -16,4 +17,4 @@ var _chunkN6B7UP6Bcjs = require('./chunk-N6B7UP6B.cjs');
|
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
exports.FetchMock =
|
|
20
|
+
exports.FetchMock = _chunkVUNESK75cjs.FetchMock; exports.MockCallHistory = _chunkVUNESK75cjs.MockCallHistory; exports.MockCallHistoryLog = _chunkVUNESK75cjs.MockCallHistoryLog; exports.NodeMswAdapter = _chunk27BEAYUIcjs.NodeMswAdapter; exports.createFetchMock = _chunk27BEAYUIcjs.createFetchMock; exports.fetchMock = _chunk27BEAYUIcjs.fetchMock;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { NodeMswAdapter, createFetchMock, fetchMock } from './node.cjs';
|
|
2
|
-
export { A as ActivateOptions, C as CallHistoryFilterCriteria, F as FetchMock, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor,
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, F as FetchMock, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor, g as ReplyCallback, h as ReplyOptions, l as SetupServerLike, i as SingleReplyCallback, j as SingleReplyResult } from './fetch-mock-1oOS8WUJ.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { NodeMswAdapter, createFetchMock, fetchMock } from './node.js';
|
|
2
|
-
export { A as ActivateOptions, C as CallHistoryFilterCriteria, F as FetchMock, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor,
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, F as FetchMock, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor, g as ReplyCallback, h as ReplyOptions, l as SetupServerLike, i as SingleReplyCallback, j as SingleReplyResult } from './fetch-mock-1oOS8WUJ.js';
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,14 @@ import {
|
|
|
2
2
|
NodeMswAdapter,
|
|
3
3
|
createFetchMock,
|
|
4
4
|
fetchMock
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-IWHL7QPE.js";
|
|
6
6
|
import "./chunk-KGCQG4D2.js";
|
|
7
|
+
import "./chunk-GZFGTCZB.js";
|
|
7
8
|
import {
|
|
8
9
|
FetchMock,
|
|
9
10
|
MockCallHistory,
|
|
10
11
|
MockCallHistoryLog
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-3XFP4NAO.js";
|
|
12
13
|
export {
|
|
13
14
|
FetchMock,
|
|
14
15
|
MockCallHistory,
|
package/dist/legacy.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkVUNESK75cjs = require('./chunk-VUNESK75.cjs');
|
|
6
6
|
|
|
7
7
|
// src/legacy-handler-factory.ts
|
|
8
8
|
function createLegacyHandlerFactory(rest) {
|
|
@@ -56,11 +56,11 @@ function createLegacyHandlerFactory(rest) {
|
|
|
56
56
|
|
|
57
57
|
// src/legacy.ts
|
|
58
58
|
function createFetchMock(rest, server) {
|
|
59
|
-
|
|
59
|
+
_chunkVUNESK75cjs.FetchMock._handlerFactory = createLegacyHandlerFactory(rest);
|
|
60
60
|
if (server) {
|
|
61
|
-
return new (0,
|
|
61
|
+
return new (0, _chunkVUNESK75cjs.FetchMock)(server);
|
|
62
62
|
}
|
|
63
|
-
return new (0,
|
|
63
|
+
return new (0, _chunkVUNESK75cjs.FetchMock)();
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
|
|
@@ -68,4 +68,4 @@ function createFetchMock(rest, server) {
|
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
exports.FetchMock =
|
|
71
|
+
exports.FetchMock = _chunkVUNESK75cjs.FetchMock; exports.MockCallHistory = _chunkVUNESK75cjs.MockCallHistory; exports.MockCallHistoryLog = _chunkVUNESK75cjs.MockCallHistoryLog; exports.createFetchMock = createFetchMock; exports.createLegacyHandlerFactory = createLegacyHandlerFactory;
|
package/dist/legacy.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as ActivateOptions, C as CallHistoryFilterCriteria, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor,
|
|
1
|
+
import { k as HttpMethod, H as HandlerFactory, l as SetupServerLike, F as FetchMock } from './fetch-mock-1oOS8WUJ.cjs';
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor, h as ReplyOptions } from './fetch-mock-1oOS8WUJ.cjs';
|
|
3
3
|
|
|
4
4
|
/** Duck-typed interface for MSW v1's `rest` API methods */
|
|
5
5
|
type LegacyRestMethod = (url: string | RegExp, resolver: (req: any, res: any, ctx: any) => any) => unknown;
|
package/dist/legacy.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as ActivateOptions, C as CallHistoryFilterCriteria, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor,
|
|
1
|
+
import { k as HttpMethod, H as HandlerFactory, l as SetupServerLike, F as FetchMock } from './fetch-mock-1oOS8WUJ.js';
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, M as MswAdapter, O as OnUnhandledRequest, P as PendingInterceptor, h as ReplyOptions } from './fetch-mock-1oOS8WUJ.js';
|
|
3
3
|
|
|
4
4
|
/** Duck-typed interface for MSW v1's `rest` API methods */
|
|
5
5
|
type LegacyRestMethod = (url: string | RegExp, resolver: (req: any, res: any, ctx: any) => any) => unknown;
|
package/dist/legacy.js
CHANGED
package/dist/native.cjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;require('./chunk-3RE2WWHX.cjs');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkVUNESK75cjs = require('./chunk-VUNESK75.cjs');
|
|
7
|
+
|
|
8
|
+
// src/native-adapter.ts
|
|
9
|
+
var NativeFetchAdapter = (_class = class {constructor() { _class.prototype.__init.call(this); }
|
|
10
|
+
|
|
11
|
+
__init() {this.handlers = []}
|
|
12
|
+
|
|
13
|
+
activate(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.originalFetch = globalThis.fetch;
|
|
16
|
+
globalThis.fetch = async (input, init) => {
|
|
17
|
+
const request = new Request(input, init);
|
|
18
|
+
for (const handler of this.handlers) {
|
|
19
|
+
const response = await handler.handlerFn(request);
|
|
20
|
+
if (response !== void 0) {
|
|
21
|
+
if (response.type === "error") {
|
|
22
|
+
throw new TypeError("Failed to fetch");
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.options.onUnhandledRequest(request, {
|
|
28
|
+
warning() {
|
|
29
|
+
console.warn(
|
|
30
|
+
`[msw-fetch-mock] Warning: intercepted a request without a matching request handler:
|
|
31
|
+
|
|
32
|
+
\u2022 ${request.method} ${request.url}
|
|
33
|
+
|
|
34
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.`
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
error() {
|
|
38
|
+
throw new TypeError(
|
|
39
|
+
`[msw-fetch-mock] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.
|
|
40
|
+
|
|
41
|
+
\u2022 ${request.method} ${request.url}
|
|
42
|
+
`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return this.originalFetch(input, init);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
deactivate() {
|
|
50
|
+
globalThis.fetch = this.originalFetch;
|
|
51
|
+
this.handlers = [];
|
|
52
|
+
}
|
|
53
|
+
use(...handlers) {
|
|
54
|
+
this.handlers.push(...handlers);
|
|
55
|
+
}
|
|
56
|
+
resetHandlers(...handlers) {
|
|
57
|
+
this.handlers = handlers;
|
|
58
|
+
}
|
|
59
|
+
}, _class);
|
|
60
|
+
|
|
61
|
+
// src/native-handler-factory.ts
|
|
62
|
+
var NativeHandlerFactory = {
|
|
63
|
+
createHandler(method, urlPattern, handlerFn) {
|
|
64
|
+
return { method, urlPattern, handlerFn };
|
|
65
|
+
},
|
|
66
|
+
buildResponse(status, body, headers) {
|
|
67
|
+
if (body === null || body === void 0) {
|
|
68
|
+
return new Response(null, { status, headers });
|
|
69
|
+
}
|
|
70
|
+
return Response.json(body, { status, headers });
|
|
71
|
+
},
|
|
72
|
+
buildErrorResponse() {
|
|
73
|
+
return Response.error();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/native.ts
|
|
78
|
+
_chunkVUNESK75cjs.FetchMock._defaultAdapterFactory = () => new NativeFetchAdapter();
|
|
79
|
+
_chunkVUNESK75cjs.FetchMock._handlerFactory = NativeHandlerFactory;
|
|
80
|
+
function createFetchMock() {
|
|
81
|
+
return new (0, _chunkVUNESK75cjs.FetchMock)(new NativeFetchAdapter());
|
|
82
|
+
}
|
|
83
|
+
var fetchMock = createFetchMock();
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
exports.FetchMock = _chunkVUNESK75cjs.FetchMock; exports.MockCallHistory = _chunkVUNESK75cjs.MockCallHistory; exports.MockCallHistoryLog = _chunkVUNESK75cjs.MockCallHistoryLog; exports.NativeFetchAdapter = NativeFetchAdapter; exports.NativeHandlerFactory = NativeHandlerFactory; exports.createFetchMock = createFetchMock; exports.fetchMock = fetchMock;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { M as MswAdapter, R as ResolvedActivateOptions, H as HandlerFactory, F as FetchMock } from './fetch-mock-1oOS8WUJ.cjs';
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, O as OnUnhandledRequest, P as PendingInterceptor, g as ReplyCallback, h as ReplyOptions, i as SingleReplyCallback, j as SingleReplyResult } from './fetch-mock-1oOS8WUJ.cjs';
|
|
3
|
+
|
|
4
|
+
declare class NativeFetchAdapter implements MswAdapter {
|
|
5
|
+
private originalFetch;
|
|
6
|
+
private handlers;
|
|
7
|
+
private options;
|
|
8
|
+
activate(options: ResolvedActivateOptions): void;
|
|
9
|
+
deactivate(): void;
|
|
10
|
+
use(...handlers: unknown[]): void;
|
|
11
|
+
resetHandlers(...handlers: unknown[]): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare const NativeHandlerFactory: HandlerFactory;
|
|
15
|
+
|
|
16
|
+
declare function createFetchMock(): FetchMock;
|
|
17
|
+
/** Pre-built singleton for quick standalone use. */
|
|
18
|
+
declare const fetchMock: FetchMock;
|
|
19
|
+
|
|
20
|
+
export { FetchMock, HandlerFactory, MswAdapter, NativeFetchAdapter, NativeHandlerFactory, createFetchMock, fetchMock };
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { M as MswAdapter, R as ResolvedActivateOptions, H as HandlerFactory, F as FetchMock } from './fetch-mock-1oOS8WUJ.js';
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, O as OnUnhandledRequest, P as PendingInterceptor, g as ReplyCallback, h as ReplyOptions, i as SingleReplyCallback, j as SingleReplyResult } from './fetch-mock-1oOS8WUJ.js';
|
|
3
|
+
|
|
4
|
+
declare class NativeFetchAdapter implements MswAdapter {
|
|
5
|
+
private originalFetch;
|
|
6
|
+
private handlers;
|
|
7
|
+
private options;
|
|
8
|
+
activate(options: ResolvedActivateOptions): void;
|
|
9
|
+
deactivate(): void;
|
|
10
|
+
use(...handlers: unknown[]): void;
|
|
11
|
+
resetHandlers(...handlers: unknown[]): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare const NativeHandlerFactory: HandlerFactory;
|
|
15
|
+
|
|
16
|
+
declare function createFetchMock(): FetchMock;
|
|
17
|
+
/** Pre-built singleton for quick standalone use. */
|
|
18
|
+
declare const fetchMock: FetchMock;
|
|
19
|
+
|
|
20
|
+
export { FetchMock, HandlerFactory, MswAdapter, NativeFetchAdapter, NativeHandlerFactory, createFetchMock, fetchMock };
|
package/dist/native.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import "./chunk-GZFGTCZB.js";
|
|
2
|
+
import {
|
|
3
|
+
FetchMock,
|
|
4
|
+
MockCallHistory,
|
|
5
|
+
MockCallHistoryLog
|
|
6
|
+
} from "./chunk-3XFP4NAO.js";
|
|
7
|
+
|
|
8
|
+
// src/native-adapter.ts
|
|
9
|
+
var NativeFetchAdapter = class {
|
|
10
|
+
originalFetch;
|
|
11
|
+
handlers = [];
|
|
12
|
+
options;
|
|
13
|
+
activate(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.originalFetch = globalThis.fetch;
|
|
16
|
+
globalThis.fetch = async (input, init) => {
|
|
17
|
+
const request = new Request(input, init);
|
|
18
|
+
for (const handler of this.handlers) {
|
|
19
|
+
const response = await handler.handlerFn(request);
|
|
20
|
+
if (response !== void 0) {
|
|
21
|
+
if (response.type === "error") {
|
|
22
|
+
throw new TypeError("Failed to fetch");
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.options.onUnhandledRequest(request, {
|
|
28
|
+
warning() {
|
|
29
|
+
console.warn(
|
|
30
|
+
`[msw-fetch-mock] Warning: intercepted a request without a matching request handler:
|
|
31
|
+
|
|
32
|
+
\u2022 ${request.method} ${request.url}
|
|
33
|
+
|
|
34
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.`
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
error() {
|
|
38
|
+
throw new TypeError(
|
|
39
|
+
`[msw-fetch-mock] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.
|
|
40
|
+
|
|
41
|
+
\u2022 ${request.method} ${request.url}
|
|
42
|
+
`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return this.originalFetch(input, init);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
deactivate() {
|
|
50
|
+
globalThis.fetch = this.originalFetch;
|
|
51
|
+
this.handlers = [];
|
|
52
|
+
}
|
|
53
|
+
use(...handlers) {
|
|
54
|
+
this.handlers.push(...handlers);
|
|
55
|
+
}
|
|
56
|
+
resetHandlers(...handlers) {
|
|
57
|
+
this.handlers = handlers;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/native-handler-factory.ts
|
|
62
|
+
var NativeHandlerFactory = {
|
|
63
|
+
createHandler(method, urlPattern, handlerFn) {
|
|
64
|
+
return { method, urlPattern, handlerFn };
|
|
65
|
+
},
|
|
66
|
+
buildResponse(status, body, headers) {
|
|
67
|
+
if (body === null || body === void 0) {
|
|
68
|
+
return new Response(null, { status, headers });
|
|
69
|
+
}
|
|
70
|
+
return Response.json(body, { status, headers });
|
|
71
|
+
},
|
|
72
|
+
buildErrorResponse() {
|
|
73
|
+
return Response.error();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/native.ts
|
|
78
|
+
FetchMock._defaultAdapterFactory = () => new NativeFetchAdapter();
|
|
79
|
+
FetchMock._handlerFactory = NativeHandlerFactory;
|
|
80
|
+
function createFetchMock() {
|
|
81
|
+
return new FetchMock(new NativeFetchAdapter());
|
|
82
|
+
}
|
|
83
|
+
var fetchMock = createFetchMock();
|
|
84
|
+
export {
|
|
85
|
+
FetchMock,
|
|
86
|
+
MockCallHistory,
|
|
87
|
+
MockCallHistoryLog,
|
|
88
|
+
NativeFetchAdapter,
|
|
89
|
+
NativeHandlerFactory,
|
|
90
|
+
createFetchMock,
|
|
91
|
+
fetchMock
|
|
92
|
+
};
|
package/dist/node.cjs
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk27BEAYUIcjs = require('./chunk-27BEAYUI.cjs');
|
|
6
6
|
require('./chunk-LVGXTY6J.cjs');
|
|
7
|
+
require('./chunk-3RE2WWHX.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _chunkVUNESK75cjs = require('./chunk-VUNESK75.cjs');
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
|
|
@@ -16,4 +17,4 @@ var _chunkN6B7UP6Bcjs = require('./chunk-N6B7UP6B.cjs');
|
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
exports.FetchMock =
|
|
20
|
+
exports.FetchMock = _chunkVUNESK75cjs.FetchMock; exports.MockCallHistory = _chunkVUNESK75cjs.MockCallHistory; exports.MockCallHistoryLog = _chunkVUNESK75cjs.MockCallHistoryLog; exports.NodeMswAdapter = _chunk27BEAYUIcjs.NodeMswAdapter; exports.createFetchMock = _chunk27BEAYUIcjs.createFetchMock; exports.fetchMock = _chunk27BEAYUIcjs.fetchMock;
|
package/dist/node.d.cts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { M as MswAdapter,
|
|
2
|
-
export { A as ActivateOptions, C as CallHistoryFilterCriteria, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, O as OnUnhandledRequest, P as PendingInterceptor,
|
|
1
|
+
import { M as MswAdapter, l as SetupServerLike, R as ResolvedActivateOptions, F as FetchMock } from './fetch-mock-1oOS8WUJ.cjs';
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, O as OnUnhandledRequest, P as PendingInterceptor, g as ReplyCallback, h as ReplyOptions, i as SingleReplyCallback, j as SingleReplyResult } from './fetch-mock-1oOS8WUJ.cjs';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* MSW adapter that owns and manages its own `setupServer` lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* **Difference from `createServerAdapter` (in fetch-mock.ts):**
|
|
8
|
+
* - `NodeMswAdapter` creates a `setupServer()` on `activate()` and calls
|
|
9
|
+
* `close()` on `deactivate()` — it owns the server lifecycle.
|
|
10
|
+
* - `createServerAdapter` wraps a user-provided server and does not manage
|
|
11
|
+
* its lifecycle — the caller owns `listen()` / `close()`.
|
|
12
|
+
*
|
|
13
|
+
* When an external server is passed via the constructor, `NodeMswAdapter`
|
|
14
|
+
* delegates to it without managing lifecycle (similar to `createServerAdapter`).
|
|
15
|
+
*/
|
|
4
16
|
declare class NodeMswAdapter implements MswAdapter {
|
|
5
17
|
private server;
|
|
6
18
|
private readonly ownsServer;
|
package/dist/node.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { M as MswAdapter,
|
|
2
|
-
export { A as ActivateOptions, C as CallHistoryFilterCriteria, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, O as OnUnhandledRequest, P as PendingInterceptor,
|
|
1
|
+
import { M as MswAdapter, l as SetupServerLike, R as ResolvedActivateOptions, F as FetchMock } from './fetch-mock-1oOS8WUJ.js';
|
|
2
|
+
export { A as ActivateOptions, C as CallHistoryFilterCriteria, H as HandlerFactory, I as InterceptOptions, a as MockCallHistory, b as MockCallHistoryLog, c as MockCallHistoryLogData, d as MockInterceptor, e as MockPool, f as MockReplyChain, O as OnUnhandledRequest, P as PendingInterceptor, g as ReplyCallback, h as ReplyOptions, i as SingleReplyCallback, j as SingleReplyResult } from './fetch-mock-1oOS8WUJ.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* MSW adapter that owns and manages its own `setupServer` lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* **Difference from `createServerAdapter` (in fetch-mock.ts):**
|
|
8
|
+
* - `NodeMswAdapter` creates a `setupServer()` on `activate()` and calls
|
|
9
|
+
* `close()` on `deactivate()` — it owns the server lifecycle.
|
|
10
|
+
* - `createServerAdapter` wraps a user-provided server and does not manage
|
|
11
|
+
* its lifecycle — the caller owns `listen()` / `close()`.
|
|
12
|
+
*
|
|
13
|
+
* When an external server is passed via the constructor, `NodeMswAdapter`
|
|
14
|
+
* delegates to it without managing lifecycle (similar to `createServerAdapter`).
|
|
15
|
+
*/
|
|
4
16
|
declare class NodeMswAdapter implements MswAdapter {
|
|
5
17
|
private server;
|
|
6
18
|
private readonly ownsServer;
|
package/dist/node.js
CHANGED
|
@@ -2,13 +2,14 @@ import {
|
|
|
2
2
|
NodeMswAdapter,
|
|
3
3
|
createFetchMock,
|
|
4
4
|
fetchMock
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-IWHL7QPE.js";
|
|
6
6
|
import "./chunk-KGCQG4D2.js";
|
|
7
|
+
import "./chunk-GZFGTCZB.js";
|
|
7
8
|
import {
|
|
8
9
|
FetchMock,
|
|
9
10
|
MockCallHistory,
|
|
10
11
|
MockCallHistoryLog
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-3XFP4NAO.js";
|
|
12
13
|
export {
|
|
13
14
|
FetchMock,
|
|
14
15
|
MockCallHistory,
|