msw 0.36.3 → 0.36.8

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 CHANGED
@@ -1,5 +1,7 @@
1
+ <br />
2
+
1
3
  <p align="center">
2
- <img src="media/msw-logo.svg" width="120" alt="Mock Service Worker logo" />
4
+ <img src="media/msw-logo.svg" width="100" alt="Mock Service Worker logo" />
3
5
  </p>
4
6
 
5
7
  <h1 align="center">Mock Service Worker</h1>
@@ -56,7 +58,7 @@ Browser usage is what sets Mock Service Worker apart from other tools. Utilizing
56
58
 
57
59
  **Watch a 30 seconds explanation on how Mock Service Worker works in a browser:**
58
60
 
59
- [![What is Mock Service Worker?](https://raw.githubusercontent.com/mswjs/msw/master/media/msw-video-thumbnail.jpg)](https://youtu.be/HcQCqboatZk)
61
+ [![What is Mock Service Worker?](https://raw.githubusercontent.com/mswjs/msw/main/media/msw-video-thumbnail.jpg)](https://youtu.be/HcQCqboatZk)
60
62
 
61
63
  ### How is it different?
62
64
 
@@ -91,7 +93,7 @@ worker.start()
91
93
 
92
94
  Performing a `GET https://github.com/octocat` request in your application will result into a mocked response that you can inspect in your browser's "Network" tab:
93
95
 
94
- ![Chrome DevTools Network screenshot with the request mocked](https://github.com/open-draft/msw/blob/master/media/msw-quick-look-network.png?raw=true)
96
+ ![Chrome DevTools Network screenshot with the request mocked](https://github.com/mswjs/msw/blob/main/media/msw-quick-look-network.png?raw=true)
95
97
 
96
98
  > **Tip:** Did you know that although Service Worker runs in a separate thread, your mock definition executes on the client-side? That way you can use the same languages (i.e. TypeScript), third-party libraries, and internal logic in mocks.
97
99
 
@@ -188,8 +190,45 @@ test('handles login exception', () => {
188
190
 
189
191
  > **Tip:** Did you know that although the API is called `setupServer`, there are no actual servers involved? The name is chosen for familiarity, and the API is designed to resemble operating with an actual server.
190
192
 
191
- ## Awards & Mentions
193
+ ## Sponsors
192
194
 
193
- <br />
195
+ ### Golden Sponsors
196
+
197
+ > Become our first golden sponsor and get featured right here, enjoying other perks like issue prioritization and a personal consulting session with us.
198
+ >
199
+ > **Learn more on our [GitHub Sponsors profile](https://github.com/sponsors/mswjs)**.
200
+
201
+ ### Silver Sponsors
202
+
203
+ > Become our first _silver sponsor_ and get your profile image and link featured right here.
204
+ >
205
+ > **Learn more on our [GitHub Sponsors profile](https://github.com/sponsors/mswjs)**.
206
+
207
+ ### Bronze Sponsors
208
+
209
+ > Become our first _bronze sponsor_ and get your profile image and link featured in this section.
210
+ >
211
+ > **Learn more on our [GitHub Sponsors profile](https://github.com/sponsors/mswjs)**.
212
+
213
+ ## Awards & Mentions
194
214
 
195
- <img src="https://raw.githubusercontent.com/open-draft/msw/master/media/os-awards-2020.png" width="160" alt="Open Source Awards 2020" />
215
+ <table>
216
+ <tr valign="middle">
217
+ <td width="124">
218
+ <img src="https://raw.githubusercontent.com/mswjs/msw/main/media/tech-radar.png" width="124" alt="Technology Radar">
219
+ </td>
220
+ <td>
221
+ <h4>Solution Worth Pursuing</h4>
222
+ <p><em><a href="https://www.thoughtworks.com/radar/languages-and-frameworks/mock-service-worker">Technology Radar</a> (2020–2021)</em></p>
223
+ </td>
224
+ </tr>
225
+ <tr>
226
+ <td width="124">
227
+ <img src="https://raw.githubusercontent.com/mswjs/msw/main/media/os-awards.png" width="124" alt="Open Source Awards 2020">
228
+ </td>
229
+ <td>
230
+ <h4>The Most Exciting Use of Technology</h4>
231
+ <p><em><a href="https://osawards.com/javascript/2020">Open Source Awards</a> (2020)</em></p>
232
+ </td>
233
+ </tr>
234
+ </table>
@@ -136,11 +136,9 @@ var InvariantError = /** @class */ (function (_super) {
136
136
  _this.name = 'Invariant Violation';
137
137
  _this.message = format_1.format.apply(void 0, __spreadArray([message], positionals));
138
138
  if (_this.stack) {
139
- var prevStack = _this.stack;
140
- _this.stack = prevStack
141
- .split('\n')
142
- .slice(STACK_FRAMES_TO_IGNORE)
143
- .join('\n');
139
+ var nextStack = _this.stack.split('\n');
140
+ nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
141
+ _this.stack = nextStack.join('\n');
144
142
  }
145
143
  return _this;
146
144
  }
@@ -283,11 +281,12 @@ function parseMultipartData(data, headers) {
283
281
  * Parses a given request/response body based on the "Content-Type" header.
284
282
  */
285
283
  function parseBody(body, headers) {
284
+ var _a;
286
285
  // Return whatever falsey body value is given.
287
286
  if (!body) {
288
287
  return body;
289
288
  }
290
- const contentType = (headers === null || headers === void 0 ? void 0 : headers.get('content-type')) || '';
289
+ const contentType = ((_a = headers === null || headers === void 0 ? void 0 : headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
291
290
  // If the body has a Multipart Content-Type
292
291
  // parse it into an object.
293
292
  const hasMultipartContent = contentType.startsWith('multipart/form-data');
@@ -707,12 +706,23 @@ function cleanUrl(path) {
707
706
  return path.replace(REDUNDANT_CHARACTERS_EXP, '');
708
707
  }
709
708
 
709
+ /**
710
+ * Determines if the given URL string is an absolute URL.
711
+ */
712
+ function isAbsoluteUrl(url) {
713
+ return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
714
+ }
715
+
710
716
  /**
711
717
  * Returns an absolute URL based on the given path.
712
718
  */
713
719
  function getAbsoluteUrl(path, baseUrl) {
714
- // Ignore absolute URLs.
715
- if (!path.startsWith('/')) {
720
+ // already absolute URL
721
+ if (isAbsoluteUrl(path)) {
722
+ return path;
723
+ }
724
+ // Ignore path with pattern start with *
725
+ if (path.startsWith('*')) {
716
726
  return path;
717
727
  }
718
728
  // Resolve a relative request URL against a given custom "baseUrl"
@@ -760,12 +770,17 @@ function coercePath(path) {
760
770
  ? `${parameterName}${wildcard}`
761
771
  : `${parameterName}${expression}`;
762
772
  })
773
+ /**
774
+ * Escape the port so that "path-to-regexp" can match
775
+ * absolute URLs including port numbers.
776
+ */
777
+ .replace(/([^\/])(:)(?=\d+)/, '$1\\$2')
763
778
  /**
764
779
  * Escape the protocol so that "path-to-regexp" could match
765
780
  * absolute URL.
766
781
  * @see https://github.com/pillarjs/path-to-regexp/issues/259
767
782
  */
768
- .replace(/^([^\/]+)(:)(?=\/\/)/g, '$1\\$2'));
783
+ .replace(/^([^\/]+)(:)(?=\/\/)/, '$1\\$2'));
769
784
  }
770
785
  /**
771
786
  * Returns the result of matching given request URL against a mask.
@@ -974,7 +974,9 @@ const createFetchRequestParameters = (input) => {
974
974
  if (['GET', 'HEAD'].includes(method)) {
975
975
  return requestParameters;
976
976
  }
977
- if (typeof body === 'object' || typeof body === 'number') {
977
+ if (typeof body === 'object' ||
978
+ typeof body === 'number' ||
979
+ typeof body === 'boolean') {
978
980
  requestParameters.body = JSON.stringify(body);
979
981
  }
980
982
  else {
@@ -2,7 +2,7 @@
2
2
  /* tslint:disable */
3
3
 
4
4
  /**
5
- * Mock Service Worker (0.36.3).
5
+ * Mock Service Worker (0.36.8).
6
6
  * @see https://github.com/mswjs/msw
7
7
  * - Please do NOT modify this file.
8
8
  * - Please do NOT serve this file on production.