msw 0.24.0 → 0.24.1

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/native/index.js CHANGED
@@ -2315,6 +2315,13 @@ var statuses = {
2315
2315
  "511": "Network Authentication Required"
2316
2316
  };
2317
2317
 
2318
+ /**
2319
+ * Sets a response status code and text.
2320
+ * @example
2321
+ * res(ctx.status(301))
2322
+ * res(ctx.status(400, 'Custom status text'))
2323
+ * @see {@link https://mswjs.io/docs/api/context/status `ctx.status()`}
2324
+ */
2318
2325
  const status = (statusCode, statusText) => {
2319
2326
  return (res) => {
2320
2327
  res.status = statusCode;
@@ -2324,6 +2331,10 @@ const status = (statusCode, statusText) => {
2324
2331
  };
2325
2332
  };
2326
2333
 
2334
+ /**
2335
+ * Sets one or multiple response headers.
2336
+ * @see {@link https://mswjs.io/docs/api/context/set `ctx.set()`}
2337
+ */
2327
2338
  function set(...args) {
2328
2339
  return (res) => {
2329
2340
  const [name, value] = args;
@@ -2367,10 +2378,11 @@ const getRandomServerResponseTime = () => {
2367
2378
  MIN_SERVER_RESPONSE_TIME);
2368
2379
  };
2369
2380
  /**
2370
- * Delays the current response for the given duration (in ms)
2381
+ * Delays the response by the given duration (ms).
2371
2382
  * @example
2372
- * res(delay()) // realistic server response time
2373
- * res(delay(1500)) // explicit response delay duration
2383
+ * res(ctx.delay()) // realistic server response time
2384
+ * res(ctx.delay(1200))
2385
+ * @see {@link https://mswjs.io/docs/api/context/delay `ctx.delay()`}
2374
2386
  */
2375
2387
  const delay = (durationMs) => {
2376
2388
  return (res) => {
@@ -2396,9 +2408,10 @@ const createFetchRequestParameters = (input) => {
2396
2408
  return requestParameters;
2397
2409
  };
2398
2410
  /**
2399
- * Wrapper around the native `window.fetch()` function that performs
2400
- * a request bypassing MSW. Requests performed using
2401
- * this function will never be mocked.
2411
+ * Performs a bypassed request inside a request handler.
2412
+ * @example
2413
+ * const originalResponse = await ctx.fetch(req)
2414
+ * @see {@link https://mswjs.io/docs/api/context/fetch `ctx.fetch()`}
2402
2415
  */
2403
2416
  const fetch = (input, requestInit = {}) => {
2404
2417
  // Keep the default `window.fetch()` call signature
@@ -3979,9 +3992,6 @@ const DEFAULT_LISTEN_OPTIONS = {
3979
3992
  * Useful to generate identical API using different patches to request issuing modules.
3980
3993
  */
3981
3994
  function createSetupServer(...interceptors) {
3982
- /**
3983
- * Sets up a server-side requests interception with the given mock definition.
3984
- */
3985
3995
  return function setupServer(...requestHandlers) {
3986
3996
  requestHandlers.forEach((handler) => {
3987
3997
  if (Array.isArray(handler))
package/node/index.js CHANGED
@@ -2317,6 +2317,13 @@ var statuses = {
2317
2317
  "511": "Network Authentication Required"
2318
2318
  };
2319
2319
 
2320
+ /**
2321
+ * Sets a response status code and text.
2322
+ * @example
2323
+ * res(ctx.status(301))
2324
+ * res(ctx.status(400, 'Custom status text'))
2325
+ * @see {@link https://mswjs.io/docs/api/context/status `ctx.status()`}
2326
+ */
2320
2327
  const status = (statusCode, statusText) => {
2321
2328
  return (res) => {
2322
2329
  res.status = statusCode;
@@ -2326,6 +2333,10 @@ const status = (statusCode, statusText) => {
2326
2333
  };
2327
2334
  };
2328
2335
 
2336
+ /**
2337
+ * Sets one or multiple response headers.
2338
+ * @see {@link https://mswjs.io/docs/api/context/set `ctx.set()`}
2339
+ */
2329
2340
  function set(...args) {
2330
2341
  return (res) => {
2331
2342
  const [name, value] = args;
@@ -2369,10 +2380,11 @@ const getRandomServerResponseTime = () => {
2369
2380
  MIN_SERVER_RESPONSE_TIME);
2370
2381
  };
2371
2382
  /**
2372
- * Delays the current response for the given duration (in ms)
2383
+ * Delays the response by the given duration (ms).
2373
2384
  * @example
2374
- * res(delay()) // realistic server response time
2375
- * res(delay(1500)) // explicit response delay duration
2385
+ * res(ctx.delay()) // realistic server response time
2386
+ * res(ctx.delay(1200))
2387
+ * @see {@link https://mswjs.io/docs/api/context/delay `ctx.delay()`}
2376
2388
  */
2377
2389
  const delay = (durationMs) => {
2378
2390
  return (res) => {
@@ -2398,9 +2410,10 @@ const createFetchRequestParameters = (input) => {
2398
2410
  return requestParameters;
2399
2411
  };
2400
2412
  /**
2401
- * Wrapper around the native `window.fetch()` function that performs
2402
- * a request bypassing MSW. Requests performed using
2403
- * this function will never be mocked.
2413
+ * Performs a bypassed request inside a request handler.
2414
+ * @example
2415
+ * const originalResponse = await ctx.fetch(req)
2416
+ * @see {@link https://mswjs.io/docs/api/context/fetch `ctx.fetch()`}
2404
2417
  */
2405
2418
  const fetch = (input, requestInit = {}) => {
2406
2419
  // Keep the default `window.fetch()` call signature
@@ -3981,9 +3994,6 @@ const DEFAULT_LISTEN_OPTIONS = {
3981
3994
  * Useful to generate identical API using different patches to request issuing modules.
3982
3995
  */
3983
3996
  function createSetupServer(...interceptors) {
3984
- /**
3985
- * Sets up a server-side requests interception with the given mock definition.
3986
- */
3987
3997
  return function setupServer(...requestHandlers) {
3988
3998
  requestHandlers.forEach((handler) => {
3989
3999
  if (Array.isArray(handler))
@@ -4083,6 +4093,11 @@ ${source.bold(meta.header)}
4083
4093
  };
4084
4094
  }
4085
4095
 
4096
+ /**
4097
+ * Sets up a requests interception in NodeJS with the given request handlers.
4098
+ * @param {RequestHandler[]} requestHandlers List of request handlers.
4099
+ * @see {@link https://mswjs.io/docs/api/setup-server `setupServer`}
4100
+ */
4086
4101
  const setupServer = createSetupServer(ClientRequest.interceptClientRequest, XMLHttpRequest.interceptXMLHttpRequest);
4087
4102
 
4088
4103
  exports.setupServer = setupServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
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",