msw 0.21.2 → 0.21.3

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/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Change Log
2
+
3
+ This project adheres to [Semantic Versioning](https://semver.org/).
4
+ Every release, along with the migration instructions, is documented on the Github [Releases](https://github.com/mswjs/msw/releases) page.
@@ -82,11 +82,11 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
82
82
 
83
83
  function createCommonjsModule(fn, basedir, module) {
84
84
  return module = {
85
- path: basedir,
86
- exports: {},
87
- require: function (path, base) {
88
- return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
89
- }
85
+ path: basedir,
86
+ exports: {},
87
+ require: function (path, base) {
88
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
89
+ }
90
90
  }, fn(module, module.exports), module.exports;
91
91
  }
92
92
 
package/lib/esm/index.js CHANGED
@@ -9,18 +9,18 @@ export { m as matchRequestUrl } from './matchRequestUrl-deps.js';
9
9
  export { graphql, graphqlContext } from './graphql.js';
10
10
 
11
11
  /*! *****************************************************************************
12
- Copyright (c) Microsoft Corporation. All rights reserved.
13
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
14
- this file except in compliance with the License. You may obtain a copy of the
15
- License at http://www.apache.org/licenses/LICENSE-2.0
12
+ Copyright (c) Microsoft Corporation.
16
13
 
17
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
19
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
20
- MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ Permission to use, copy, modify, and/or distribute this software for any
15
+ purpose with or without fee is hereby granted.
21
16
 
22
- See the Apache Version 2.0 License for specific language governing permissions
23
- and limitations under the License.
17
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
+ PERFORMANCE OF THIS SOFTWARE.
24
24
  ***************************************************************************** */
25
25
 
26
26
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -632,6 +632,10 @@ function resetHandlers(initialHandlers, ...nextHandlers) {
632
632
  // so it persists between Fash refreshes of the application's code.
633
633
  let listeners = [];
634
634
  function setupWorker(...requestHandlers) {
635
+ requestHandlers.forEach((handler) => {
636
+ if (Array.isArray(handler))
637
+ throw new Error(`[MSW] Failed to call "setupWorker" given an Array of request handlers (setupWorker([a, b])), expected to receive each handler individually: setupWorker(a, b).`);
638
+ });
635
639
  const context = {
636
640
  worker: null,
637
641
  registration: null,
@@ -0,0 +1,17 @@
1
+ export declare class LiveStorage<Value> {
2
+ name: string;
3
+ value: Value;
4
+ channel: BroadcastChannel;
5
+ constructor(name: string, initialValue: Value);
6
+ getValue: () => Value;
7
+ update: (applyUpdate: (prevValue: Value) => Value) => void;
8
+ private broadcastValue;
9
+ /**
10
+ * Flush the value into the presistency layer.
11
+ */
12
+ private persist;
13
+ /**
14
+ * Hydrate the value from the persistency layer.
15
+ */
16
+ private hydrate;
17
+ }
@@ -27,7 +27,7 @@ export interface GraphQLRequestPayload<VariablesType> {
27
27
  query: string;
28
28
  variables?: VariablesType;
29
29
  }
30
- interface GraphQLRequestParsedResult<VariablesType> {
30
+ export interface GraphQLRequestParsedResult<VariablesType> {
31
31
  operationType: OperationTypeNode;
32
32
  operationName: string | undefined;
33
33
  variables: VariablesType | undefined;
@@ -4,5 +4,5 @@ export { MockedResponse, ResponseTransformer, response } from './response';
4
4
  export { context };
5
5
  export { MockedRequest, RequestHandler, RequestParams, RequestQuery, ResponseResolver, ResponseResolverReturnType, AsyncResponseResolverReturnType, defaultContext, } from './utils/handlers/requestHandler';
6
6
  export { rest, restContext, RESTMethods, ParsedRestRequest } from './rest';
7
- export { graphql, graphqlContext, GraphQLMockedRequest, GraphQLMockedContext, GraphQLRequestPayload, GraphQLResponseResolver, } from './graphql';
7
+ export { graphql, graphqlContext, GraphQLMockedRequest, GraphQLMockedContext, GraphQLRequestPayload, GraphQLResponseResolver, GraphQLRequestParsedResult, } from './graphql';
8
8
  export { matchRequestUrl } from './utils/matching/matchRequestUrl';
@@ -1,4 +1,4 @@
1
- import { RequestHandler, ResponseResolver, MockedRequest, DefaultRequestBodyType } from './utils/handlers/requestHandler';
1
+ import { RequestHandler, ResponseResolver, MockedRequest, DefaultRequestBodyType, RequestParams } from './utils/handlers/requestHandler';
2
2
  import { Mask } from './setupWorker/glossary';
3
3
  import { set } from './context/set';
4
4
  import { matchRequestUrl } from './utils/matching/matchRequestUrl';
@@ -20,13 +20,13 @@ export declare const restContext: {
20
20
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
21
21
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
22
22
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
23
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
23
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
24
24
  };
25
25
  export interface ParsedRestRequest {
26
26
  match: ReturnType<typeof matchRequestUrl>;
27
27
  }
28
28
  export declare const rest: {
29
- head: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType>, {
29
+ head: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any, RequestParamsType extends RequestParams = RequestParams>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType, RequestParamsType>, {
30
30
  set: typeof set;
31
31
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
32
32
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -35,8 +35,8 @@ export declare const rest: {
35
35
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
36
36
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
37
37
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
38
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
39
- }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType>, {
38
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
39
+ }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType, RequestParamsType>, {
40
40
  set: typeof set;
41
41
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
42
42
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -45,9 +45,9 @@ export declare const rest: {
45
45
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
46
46
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
47
47
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
48
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
49
- }, ParsedRestRequest, MockedRequest<RequestBodyType>, ResponseBodyType>;
50
- get: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType>, {
48
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
49
+ }, ParsedRestRequest, MockedRequest<RequestBodyType, RequestParams>, ResponseBodyType>;
50
+ get: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any, RequestParamsType extends RequestParams = RequestParams>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType, RequestParamsType>, {
51
51
  set: typeof set;
52
52
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
53
53
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -56,8 +56,8 @@ export declare const rest: {
56
56
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
57
57
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
58
58
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
59
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
60
- }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType>, {
59
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
60
+ }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType, RequestParamsType>, {
61
61
  set: typeof set;
62
62
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
63
63
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -66,9 +66,9 @@ export declare const rest: {
66
66
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
67
67
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
68
68
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
69
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
70
- }, ParsedRestRequest, MockedRequest<RequestBodyType>, ResponseBodyType>;
71
- post: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType>, {
69
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
70
+ }, ParsedRestRequest, MockedRequest<RequestBodyType, RequestParams>, ResponseBodyType>;
71
+ post: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any, RequestParamsType extends RequestParams = RequestParams>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType, RequestParamsType>, {
72
72
  set: typeof set;
73
73
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
74
74
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -77,8 +77,8 @@ export declare const rest: {
77
77
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
78
78
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
79
79
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
80
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
81
- }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType>, {
80
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
81
+ }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType, RequestParamsType>, {
82
82
  set: typeof set;
83
83
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
84
84
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -87,9 +87,9 @@ export declare const rest: {
87
87
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
88
88
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
89
89
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
90
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
91
- }, ParsedRestRequest, MockedRequest<RequestBodyType>, ResponseBodyType>;
92
- put: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType>, {
90
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
91
+ }, ParsedRestRequest, MockedRequest<RequestBodyType, RequestParams>, ResponseBodyType>;
92
+ put: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any, RequestParamsType extends RequestParams = RequestParams>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType, RequestParamsType>, {
93
93
  set: typeof set;
94
94
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
95
95
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -98,8 +98,8 @@ export declare const rest: {
98
98
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
99
99
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
100
100
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
101
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
102
- }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType>, {
101
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
102
+ }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType, RequestParamsType>, {
103
103
  set: typeof set;
104
104
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
105
105
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -108,9 +108,9 @@ export declare const rest: {
108
108
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
109
109
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
110
110
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
111
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
112
- }, ParsedRestRequest, MockedRequest<RequestBodyType>, ResponseBodyType>;
113
- delete: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType>, {
111
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
112
+ }, ParsedRestRequest, MockedRequest<RequestBodyType, RequestParams>, ResponseBodyType>;
113
+ delete: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any, RequestParamsType extends RequestParams = RequestParams>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType, RequestParamsType>, {
114
114
  set: typeof set;
115
115
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
116
116
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -119,8 +119,8 @@ export declare const rest: {
119
119
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
120
120
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
121
121
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
122
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
123
- }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType>, {
122
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
123
+ }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType, RequestParamsType>, {
124
124
  set: typeof set;
125
125
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
126
126
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -129,9 +129,9 @@ export declare const rest: {
129
129
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
130
130
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
131
131
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
132
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
133
- }, ParsedRestRequest, MockedRequest<RequestBodyType>, ResponseBodyType>;
134
- patch: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType>, {
132
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
133
+ }, ParsedRestRequest, MockedRequest<RequestBodyType, RequestParams>, ResponseBodyType>;
134
+ patch: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any, RequestParamsType extends RequestParams = RequestParams>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType, RequestParamsType>, {
135
135
  set: typeof set;
136
136
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
137
137
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -140,8 +140,8 @@ export declare const rest: {
140
140
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
141
141
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
142
142
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
143
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
144
- }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType>, {
143
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
144
+ }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType, RequestParamsType>, {
145
145
  set: typeof set;
146
146
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
147
147
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -150,9 +150,9 @@ export declare const rest: {
150
150
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
151
151
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
152
152
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
153
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
154
- }, ParsedRestRequest, MockedRequest<RequestBodyType>, ResponseBodyType>;
155
- options: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType>, {
153
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
154
+ }, ParsedRestRequest, MockedRequest<RequestBodyType, RequestParams>, ResponseBodyType>;
155
+ options: <RequestBodyType = DefaultRequestBodyType, ResponseBodyType = any, RequestParamsType extends RequestParams = RequestParams>(mask: Mask, resolver: ResponseResolver<MockedRequest<RequestBodyType, RequestParamsType>, {
156
156
  set: typeof set;
157
157
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
158
158
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -161,8 +161,8 @@ export declare const rest: {
161
161
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
162
162
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
163
163
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
164
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
165
- }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType>, {
164
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
165
+ }, ResponseBodyType>) => RequestHandler<MockedRequest<RequestBodyType, RequestParamsType>, {
166
166
  set: typeof set;
167
167
  status: (statusCode: number, statusText?: string | undefined) => import("./response").ResponseTransformer<any>;
168
168
  cookie: (name: string, value: string, options?: import("cookie").CookieSerializeOptions | undefined) => import("./response").ResponseTransformer<any>;
@@ -171,6 +171,6 @@ export declare const rest: {
171
171
  json: <BodyType_2>(body: BodyType_2) => import("./response").ResponseTransformer<BodyType_2>;
172
172
  xml: <BodyType_3 extends string>(body: BodyType_3) => import("./response").ResponseTransformer<BodyType_3>;
173
173
  delay: (durationMs?: number | undefined) => import("./response").ResponseTransformer<any>;
174
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
175
- }, ParsedRestRequest, MockedRequest<RequestBodyType>, ResponseBodyType>;
174
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
175
+ }, ParsedRestRequest, MockedRequest<RequestBodyType, RequestParams>, ResponseBodyType>;
176
176
  };
@@ -10,5 +10,5 @@ interface ResponsePayload {
10
10
  /**
11
11
  * Returns a mocked response for a given request using following request handlers.
12
12
  */
13
- export declare const getResponse: <R extends MockedRequest<import("./handlers/requestHandler").DefaultRequestBodyType>, H extends RequestHandlersList>(req: R, handlers: H) => Promise<ResponsePayload>;
13
+ export declare const getResponse: <R extends MockedRequest<import("./handlers/requestHandler").DefaultRequestBodyType, import("./handlers/requestHandler").RequestParams>, H extends RequestHandlersList>(req: R, handlers: H) => Promise<ResponsePayload>;
14
14
  export {};
@@ -6,10 +6,10 @@ export declare const defaultContext: {
6
6
  status: (statusCode: number, statusText?: string | undefined) => import("../../response").ResponseTransformer<any>;
7
7
  set: typeof set;
8
8
  delay: (durationMs?: number | undefined) => import("../../response").ResponseTransformer<any>;
9
- fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => any;
9
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType, RequestParams>, requestInit?: RequestInit) => any;
10
10
  };
11
11
  export declare type DefaultRequestBodyType = Record<string, any> | string | undefined;
12
- export interface MockedRequest<BodyType = DefaultRequestBodyType> {
12
+ export interface MockedRequest<BodyType = DefaultRequestBodyType, RequestParamsType = RequestParams> {
13
13
  url: URL;
14
14
  method: Request['method'];
15
15
  headers: Headers;
@@ -25,7 +25,7 @@ export interface MockedRequest<BodyType = DefaultRequestBodyType> {
25
25
  referrerPolicy: Request['referrerPolicy'];
26
26
  body: BodyType;
27
27
  bodyUsed: Request['bodyUsed'];
28
- params: RequestParams;
28
+ params: RequestParamsType;
29
29
  }
30
30
  export declare type RequestQuery = {
31
31
  [queryName: string]: any;
package/lib/umd/index.js CHANGED
@@ -88,11 +88,11 @@
88
88
 
89
89
  function createCommonjsModule(fn, basedir, module) {
90
90
  return module = {
91
- path: basedir,
92
- exports: {},
93
- require: function (path, base) {
94
- return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
95
- }
91
+ path: basedir,
92
+ exports: {},
93
+ require: function (path, base) {
94
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
95
+ }
96
96
  }, fn(module, module.exports), module.exports;
97
97
  }
98
98
 
@@ -728,18 +728,18 @@
728
728
  });
729
729
 
730
730
  /*! *****************************************************************************
731
- Copyright (c) Microsoft Corporation. All rights reserved.
732
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
733
- this file except in compliance with the License. You may obtain a copy of the
734
- License at http://www.apache.org/licenses/LICENSE-2.0
731
+ Copyright (c) Microsoft Corporation.
735
732
 
736
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
737
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
738
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
739
- MERCHANTABLITY OR NON-INFRINGEMENT.
733
+ Permission to use, copy, modify, and/or distribute this software for any
734
+ purpose with or without fee is hereby granted.
740
735
 
741
- See the Apache Version 2.0 License for specific language governing permissions
742
- and limitations under the License.
736
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
737
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
738
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
739
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
740
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
741
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
742
+ PERFORMANCE OF THIS SOFTWARE.
743
743
  ***************************************************************************** */
744
744
 
745
745
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -2744,6 +2744,10 @@ If this message still persists after updating, please report an issue: https://g
2744
2744
  // so it persists between Fash refreshes of the application's code.
2745
2745
  let listeners = [];
2746
2746
  function setupWorker(...requestHandlers) {
2747
+ requestHandlers.forEach((handler) => {
2748
+ if (Array.isArray(handler))
2749
+ throw new Error(`[MSW] Failed to call "setupWorker" given an Array of request handlers (setupWorker([a, b])), expected to receive each handler individually: setupWorker(a, b).`);
2750
+ });
2747
2751
  const context = {
2748
2752
  worker: null,
2749
2753
  registration: null,
package/native/index.js CHANGED
@@ -6,18 +6,18 @@ var XMLHttpRequest = require('node-request-interceptor/lib/interceptors/XMLHttpR
6
6
  var nodeRequestInterceptor = require('node-request-interceptor');
7
7
 
8
8
  /*! *****************************************************************************
9
- Copyright (c) Microsoft Corporation. All rights reserved.
10
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
11
- this file except in compliance with the License. You may obtain a copy of the
12
- License at http://www.apache.org/licenses/LICENSE-2.0
9
+ Copyright (c) Microsoft Corporation.
13
10
 
14
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17
- MERCHANTABLITY OR NON-INFRINGEMENT.
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
18
13
 
19
- See the Apache Version 2.0 License for specific language governing permissions
20
- and limitations under the License.
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
21
  ***************************************************************************** */
22
22
 
23
23
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -120,11 +120,11 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
120
120
 
121
121
  function createCommonjsModule(fn, basedir, module) {
122
122
  return module = {
123
- path: basedir,
124
- exports: {},
125
- require: function (path, base) {
126
- return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
127
- }
123
+ path: basedir,
124
+ exports: {},
125
+ require: function (path, base) {
126
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
127
+ }
128
128
  }, fn(module, module.exports), module.exports;
129
129
  }
130
130
 
@@ -2098,6 +2098,10 @@ function createSetupServer(...interceptors) {
2098
2098
  * Sets up a server-side requests interception with the given mock definition.
2099
2099
  */
2100
2100
  return function setupServer(...requestHandlers) {
2101
+ requestHandlers.forEach((handler) => {
2102
+ if (Array.isArray(handler))
2103
+ throw new Error(`[MSW] Failed to call "setupServer" given an Array of request handlers (setupServer([a, b])), expected to receive each handler individually: setupServer(a, b).`);
2104
+ });
2101
2105
  const interceptor = new nodeRequestInterceptor.RequestInterceptor(interceptors);
2102
2106
  // Error when attempting to run this function in a browser environment.
2103
2107
  if (!isNodeProcess()) {
@@ -0,0 +1,11 @@
1
+ import { ResponseTransformer } from '../response';
2
+ export declare const MIN_SERVER_RESPONSE_TIME = 100;
3
+ export declare const MAX_SERVER_RESPONSE_TIME = 400;
4
+ export declare const NODE_SERVER_RESPONSE_TIME = 5;
5
+ /**
6
+ * Delays the current response for the given duration (in ms)
7
+ * @example
8
+ * res(delay()) // realistic server response time
9
+ * res(delay(1500)) // explicit response delay duration
10
+ */
11
+ export declare const delay: (durationMs?: number | undefined) => ResponseTransformer;
@@ -0,0 +1,8 @@
1
+ import { MockedRequest } from '../utils/handlers/requestHandler';
2
+ export declare const augmentRequestInit: (requestInit: RequestInit) => RequestInit;
3
+ /**
4
+ * Wrapper around the native `window.fetch()` function that performs
5
+ * a request bypassing MSW. Requests performed using
6
+ * this function will never be mocked.
7
+ */
8
+ export declare const fetch: (input: string | MockedRequest, requestInit?: RequestInit) => Promise<Response>;
@@ -0,0 +1,2 @@
1
+ import { ResponseTransformer } from '../response';
2
+ export declare function set<N extends string | Record<string, string | string[]>>(...args: N extends string ? [N, string] : [N]): ResponseTransformer;
@@ -0,0 +1,2 @@
1
+ import { ResponseTransformer } from '../response';
2
+ export declare const status: (statusCode: number, statusText?: string | undefined) => ResponseTransformer;
package/node/index.js CHANGED
@@ -8,18 +8,18 @@ var timers = require('timers');
8
8
  var nodeRequestInterceptor = require('node-request-interceptor');
9
9
 
10
10
  /*! *****************************************************************************
11
- Copyright (c) Microsoft Corporation. All rights reserved.
12
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
13
- this file except in compliance with the License. You may obtain a copy of the
14
- License at http://www.apache.org/licenses/LICENSE-2.0
11
+ Copyright (c) Microsoft Corporation.
15
12
 
16
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
18
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
19
- MERCHANTABLITY OR NON-INFRINGEMENT.
13
+ Permission to use, copy, modify, and/or distribute this software for any
14
+ purpose with or without fee is hereby granted.
20
15
 
21
- See the Apache Version 2.0 License for specific language governing permissions
22
- and limitations under the License.
16
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
20
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
+ PERFORMANCE OF THIS SOFTWARE.
23
23
  ***************************************************************************** */
24
24
 
25
25
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -122,11 +122,11 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
122
122
 
123
123
  function createCommonjsModule(fn, basedir, module) {
124
124
  return module = {
125
- path: basedir,
126
- exports: {},
127
- require: function (path, base) {
128
- return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
129
- }
125
+ path: basedir,
126
+ exports: {},
127
+ require: function (path, base) {
128
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
129
+ }
130
130
  }, fn(module, module.exports), module.exports;
131
131
  }
132
132
 
@@ -2100,6 +2100,10 @@ function createSetupServer(...interceptors) {
2100
2100
  * Sets up a server-side requests interception with the given mock definition.
2101
2101
  */
2102
2102
  return function setupServer(...requestHandlers) {
2103
+ requestHandlers.forEach((handler) => {
2104
+ if (Array.isArray(handler))
2105
+ throw new Error(`[MSW] Failed to call "setupServer" given an Array of request handlers (setupServer([a, b])), expected to receive each handler individually: setupServer(a, b).`);
2106
+ });
2103
2107
  const interceptor = new nodeRequestInterceptor.RequestInterceptor(interceptors);
2104
2108
  // Error when attempting to run this function in a browser environment.
2105
2109
  if (!isNodeProcess()) {
@@ -0,0 +1,29 @@
1
+ import { Interceptor } from 'node-request-interceptor';
2
+ import { RequestHandlersList } from '../setupWorker/glossary';
3
+ import { SharedOptions } from '../sharedOptions';
4
+ /**
5
+ * Creates a `setupServer` API using given request interceptors.
6
+ * Useful to generate identical API using different patches to request issuing modules.
7
+ */
8
+ export declare function createSetupServer(...interceptors: Interceptor[]): (...requestHandlers: RequestHandlersList) => {
9
+ /**
10
+ * Enables requests interception based on the previously provided mock definition.
11
+ */
12
+ listen(options?: SharedOptions | undefined): void;
13
+ /**
14
+ * Prepends given request handlers to the list of existing handlers.
15
+ */
16
+ use(...handlers: RequestHandlersList): void;
17
+ /**
18
+ * Marks all request handlers that respond using `res.once()` as unused.
19
+ */
20
+ restoreHandlers(): void;
21
+ /**
22
+ * Resets request handlers to the initial list given to the `setupServer` call, or to the explicit next request handlers list, if given.
23
+ */
24
+ resetHandlers(...nextHandlers: RequestHandlersList): void;
25
+ /**
26
+ * Stops requests interception by restoring all augmented modules.
27
+ */
28
+ close(): void;
29
+ };
@@ -0,0 +1,5 @@
1
+ export { setupServer } from './setupServer'
2
+
3
+ declare module 'types/context/body.d.ts' {
4
+ export const body: string
5
+ }
@@ -0,0 +1,7 @@
1
+ export declare const setupServer: (...requestHandlers: import("../setupWorker/glossary").RequestHandlersList) => {
2
+ listen(options?: import("../sharedOptions").SharedOptions | undefined): void;
3
+ use(...handlers: import("../setupWorker/glossary").RequestHandlersList): void;
4
+ restoreHandlers(): void;
5
+ resetHandlers(...nextHandlers: import("../setupWorker/glossary").RequestHandlersList): void;
6
+ close(): void;
7
+ };
@@ -0,0 +1,25 @@
1
+ import { Headers } from 'headers-utils';
2
+ export interface MockedResponse<BodyType = any> {
3
+ body: BodyType;
4
+ status: number;
5
+ statusText: string;
6
+ headers: Headers;
7
+ once: boolean;
8
+ delay?: number;
9
+ }
10
+ export declare type ResponseTransformer<BodyType = any> = (res: MockedResponse<BodyType>) => MockedResponse<BodyType>;
11
+ declare type ResponseFunction<BodyType = any> = (...transformers: ResponseTransformer<BodyType>[]) => MockedResponse<BodyType>;
12
+ export declare type ResponseComposition<BodyType = any> = ResponseFunction<BodyType> & {
13
+ /**
14
+ * Respond using a given mocked response to the first captured request.
15
+ * Does not affect any subsequent captured requests.
16
+ */
17
+ once: ResponseFunction<BodyType>;
18
+ networkError: (message: string) => void;
19
+ };
20
+ export declare const defaultResponse: Omit<MockedResponse, 'headers'>;
21
+ export declare const response: ResponseFunction<any> & {
22
+ once: ResponseFunction<any>;
23
+ networkError(message: string): never;
24
+ };
25
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare class NetworkError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,14 @@
1
+ import { RequestHandlersList } from '../setupWorker/glossary';
2
+ import { RequestHandler, MockedRequest } from './handlers/requestHandler';
3
+ import { MockedResponse } from '../response';
4
+ interface ResponsePayload {
5
+ response: MockedResponse | null;
6
+ handler: RequestHandler<any, any> | null;
7
+ publicRequest?: any;
8
+ parsedRequest?: any;
9
+ }
10
+ /**
11
+ * Returns a mocked response for a given request using following request handlers.
12
+ */
13
+ export declare const getResponse: <R extends MockedRequest<import("./handlers/requestHandler").DefaultRequestBodyType>, H extends RequestHandlersList>(req: R, handlers: H) => Promise<ResponsePayload>;
14
+ export {};
@@ -0,0 +1,74 @@
1
+ import { Headers } from 'headers-utils';
2
+ import { ResponseWithSerializedHeaders } from '../../setupWorker/glossary';
3
+ import { ResponseComposition, MockedResponse } from '../../response';
4
+ import { set } from '../../context/set';
5
+ export declare const defaultContext: {
6
+ status: (statusCode: number, statusText?: string | undefined) => import("../../response").ResponseTransformer<any>;
7
+ set: typeof set;
8
+ delay: (durationMs?: number | undefined) => import("../../response").ResponseTransformer<any>;
9
+ fetch: (input: string | MockedRequest<DefaultRequestBodyType>, requestInit?: RequestInit) => Promise<Response>;
10
+ };
11
+ export declare type DefaultRequestBodyType = Record<string, any> | string | undefined;
12
+ export interface MockedRequest<BodyType = DefaultRequestBodyType> {
13
+ url: URL;
14
+ method: Request['method'];
15
+ headers: Headers;
16
+ cookies: Record<string, string>;
17
+ mode: Request['mode'];
18
+ keepalive: Request['keepalive'];
19
+ cache: Request['cache'];
20
+ destination: Request['destination'];
21
+ integrity: Request['integrity'];
22
+ credentials: Request['credentials'];
23
+ redirect: Request['redirect'];
24
+ referrer: Request['referrer'];
25
+ referrerPolicy: Request['referrerPolicy'];
26
+ body: BodyType;
27
+ bodyUsed: Request['bodyUsed'];
28
+ params: RequestParams;
29
+ }
30
+ export declare type RequestQuery = {
31
+ [queryName: string]: any;
32
+ };
33
+ export declare type RequestParams = {
34
+ [paramName: string]: any;
35
+ };
36
+ export declare type ResponseResolverReturnType<R> = R | undefined | void;
37
+ export declare type AsyncResponseResolverReturnType<R> = Promise<ResponseResolverReturnType<R>> | ResponseResolverReturnType<R>;
38
+ export declare type ResponseResolver<RequestType = MockedRequest, ContextType = typeof defaultContext, BodyType = any> = (req: RequestType, res: ResponseComposition<BodyType>, context: ContextType) => AsyncResponseResolverReturnType<MockedResponse<BodyType>>;
39
+ export interface RequestHandler<RequestType = MockedRequest, ContextType = typeof defaultContext, ParsedRequest = any, PublicRequest = RequestType, ResponseBodyType = any> {
40
+ /**
41
+ * Parses a captured request to retrieve additional
42
+ * information meant for internal usage in the request handler.
43
+ */
44
+ parse?: (req: RequestType) => ParsedRequest | null;
45
+ /**
46
+ * Returns a modified request with necessary public properties appended.
47
+ */
48
+ getPublicRequest?: (req: RequestType, parsedRequest: ParsedRequest) => PublicRequest;
49
+ /**
50
+ * Predicate function that decides whether a Request should be mocked.
51
+ */
52
+ predicate: (req: RequestType, parsedRequest: ParsedRequest) => boolean;
53
+ /**
54
+ * Returns a mocked response object to the captured request.
55
+ */
56
+ resolver: ResponseResolver<RequestType, ContextType, ResponseBodyType>;
57
+ /**
58
+ * Returns a map of context utility functions available
59
+ * under the `ctx` argument of request handler.
60
+ */
61
+ defineContext?: (req: PublicRequest) => ContextType;
62
+ /**
63
+ * Prints out a mocked request/response information
64
+ * upon each request capture into browser's console.
65
+ */
66
+ log: (req: PublicRequest, res: ResponseWithSerializedHeaders, handler: RequestHandler<RequestType, ContextType, ParsedRequest, PublicRequest, ResponseBodyType>, parsedRequest: ParsedRequest) => void;
67
+ /**
68
+ * Describes whether this request handler should be skipped
69
+ * when dealing with any subsequent matching requests.
70
+ */
71
+ shouldSkip?: boolean;
72
+ }
73
+ declare const _default: null;
74
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { RequestHandlersList } from '../../setupWorker/glossary';
2
+ export declare function use(currentHandlers: RequestHandlersList, ...handlers: RequestHandlersList): void;
3
+ export declare function restoreHandlers(handlers: RequestHandlersList): void;
4
+ export declare function resetHandlers(initialHandlers: RequestHandlersList, ...nextHandlers: RequestHandlersList): import("./requestHandler").RequestHandler<any, any, any, any, any>[];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Composes a given list of functions into a new function that
3
+ * executes from right to left.
4
+ */
5
+ export declare function compose(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns a boolean indicating if the current process is running in NodeJS environment.
3
+ * @see https://github.com/mswjs/msw/pull/255
4
+ */
5
+ export declare function isNodeProcess(): boolean | undefined;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Parses a given string into a JSON.
3
+ * Does not throw an exception on an invalid JSON string.
4
+ */
5
+ export declare function jsonParse<T extends Record<string, any>>(str: string): T | undefined;
@@ -0,0 +1,6 @@
1
+ import { MockedRequest } from '../handlers/requestHandler';
2
+ /**
3
+ * Returns a relative URL if the given request URL is relative to the current origin.
4
+ * Otherwise returns an absolute URL.
5
+ */
6
+ export declare const getPublicUrlFromRequest: (request: MockedRequest) => string;
@@ -0,0 +1,5 @@
1
+ import { MockedRequest } from '../handlers/requestHandler';
2
+ declare type UnhandledRequestCallback = (req: MockedRequest) => void;
3
+ export declare type OnUnhandledRequest = 'bypass' | 'warn' | 'error' | UnhandledRequestCallback;
4
+ export declare function onUnhandledRequest(request: MockedRequest, onUnhandledRequest?: OnUnhandledRequest): void;
5
+ export {};
@@ -0,0 +1,5 @@
1
+ import { MockedRequest } from '../handlers/requestHandler';
2
+ /**
3
+ * Parses a given request/response body based on the `Content-Type` header.
4
+ */
5
+ export declare function parseBody(body?: MockedRequest['body'], headers?: Headers): import("../handlers/requestHandler").DefaultRequestBodyType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "0.21.2",
3
+ "version": "0.21.3",
4
4
  "description": "Seamless REST/GraphQL API mocking library for browser and Node.",
5
5
  "main": "lib/umd/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -83,6 +83,7 @@
83
83
  "@rollup/plugin-node-resolve": "^9.0.0",
84
84
  "@rollup/plugin-replace": "^2.3.3",
85
85
  "@types/express": "^4.17.8",
86
+ "@types/fs-extra": "^9.0.1",
86
87
  "@types/jest": "^26.0.13",
87
88
  "@types/node": "^14.6.4",
88
89
  "@types/node-fetch": "^2.5.7",
@@ -98,6 +99,7 @@
98
99
  "eslint-config-prettier": "^6.11.0",
99
100
  "eslint-plugin-prettier": "^3.1.4",
100
101
  "express": "^4.17.1",
102
+ "fs-extra": "^9.0.1",
101
103
  "html-webpack-plugin": "^4.4.1",
102
104
  "husky": "^4.3.0",
103
105
  "ignore-loader": "^0.1.2",