msw

Seamless REST/GraphQL API mocking library for browser and Node.js.

MIT License

Downloads
15.7M
Stars
14.9K
Committers
153

Bot releases are hidden (Show)

msw -

Published by kettanaito almost 3 years ago

Breaking changes

  • Uses path-to-regexp for URL matching (#691, #888). This makes the path matching experience identical to such in ExpressJS, and enabled various new features:
    • Optional path segments (/foo/bar?);
    • Repeating groups (/foo/bar+).
  • Request path parameters are now annotated as ambiguous string | string[] (#999).
  • The RequestParams generic now follows the RequestBodyType generic, changing its order (#999):
rest.post<RequestBodyType, RequestParams, ResponseBodyType>() {}
  • Removes the RequestParams type (#999). Please use the PathParams type instead.
- import { RequestParams } from 'msw'
+ import { PathParams } from 'msw'
  • Relative requests are now resolved against document.baseURI (previously location.origin) in a browser-like environments (#1007, #1008).

Features

  • Adds a new rest.all() request handler (#896). This handler captures all REST API requests regardless of method.
import { rest } from 'msw'

rest.all('/api/*', (req, res, ctx) => {
  // Intercepts all requests to "/api/*"
  // regardless of their method.
})
  • Supports encoded request path components (#980).
  • Supports mocking GraphQL extensions (#981).
graphql.query('GetUser', (req, res, ctx) => {
  return res(
    ctx.extensions({
      message: 'Mocked extension',
      tracking: { version: '1.2.3' }
    })
  )
})
  • Exports SetupWorkerApi and SetupServerApi from the browser and Node.js modules respectively (#994).

Bug fixes

  • Specifies typescript as a peerDependency to control supported TypeScript versions (#985).
  • Fixes an issue that resulted in graphql.operation handler producing a warning unable to intercept anonymous operations (#918, #904).
  • Locks inquirer dependency version to 8.1.5 to propagate the fix for the Unexpected token “?” issue when using MSW CLI (#917).
  • Fixes an issue that resulted in the TypeError: Failed to execute 'XXX' on 'Response': body stream already read error when reading the original response body in the fallback mode (https://github.com/mswjs/interceptors/pull/152).

Internal

  • Lists @mswjs/cookies and @mswjs/interceptors as external packages so that their updates propagate to you automatically upon new installations of msw.
  • Updates dependencies.
msw -

Published by kettanaito about 3 years ago

Breaking changes

  • The Life-cycle events are now exposed from the .events property on the worker/server (#868).
-worker.on('request:start', listener)
+worker.events.on('request:start', listener)

-server.on('response:mocked', listener)
+server.events.on('response:mocked', listener)

Features

  • Life-cycle events now support .removeListener() and .removeAllListeners() methods (#868).
// Removes all life-cycle event listeners you've attached to this server instance.
server.events.removeAllListeners()
  • The "error" strategy of the onUnhandledRequest option now throws an exception to halt running tests (#856).

Bug fixes

  • Fixes an issue where a request handler with parenthesis in the URL wouldn't match an otherwise matching request (#857).

Security

  • Updates the @mswjs/interceptors package to propagate the xmldom security update (#876).
msw -

Published by kettanaito about 3 years ago

Features

  • Improves error messages produces by the worker (#841, #847).
msw -

Published by kettanaito about 3 years ago

Bug fixes

  • Fixes an issue when some messages from the library were ill-formatted (#844, #850).
msw -

Published by kettanaito about 3 years ago

Bug fixes

  • Fixes an issue that resulted in the "color: inherit" being present in each request log in the browser's console (#842, #843).
msw -

Published by kettanaito about 3 years ago

Bug fixes

  • Fixes an issue that resulted in the NextJS development server becoming unresponsive due to cancelled SSR from webpack HMR (#834, #837).
msw -

Published by kettanaito over 3 years ago

Features

  • Setting a Cookie/Set-Cookie response headers via ctx.set now produces a type violation (#819). Please use ctx.cookie instead.

Internal

  • Supports resolutionContext option on handleRequest API to specify the baseUrl for all relative request handler URLs (#830).
msw -

Published by kettanaito over 3 years ago

Bug fixes

  • Fixes an issue when calling setupServer in React Native thrown an exception for using it in the wrong environment (#827).
msw -

Published by kettanaito over 3 years ago

Features

  • Exports internal utilities to be used in extensions (#824);
    • parseIsomorphicRequest()
    • handleRequest()
msw -

Published by kettanaito over 3 years ago

Bug fixes

  • Fixes an issue that resulted in corrupted original response bodies if they were compressed with gzip (https://github.com/mswjs/interceptors/pull/136, #822).
  • Fixes an issue that resulted in a memory leak of event listeners when retrieving the IncomingMessage body of the original response in Node.js (https://github.com/mswjs/interceptors/pull/140, #785).
  • Fixes an issue that resulted in the "cannot run in a non-browser environment" error when running MSW in an Electron renderer process (#661, #817, #823).
msw - v0.32.0

Published by kettanaito over 3 years ago

Bug fixes

Internals

  • Updates package dependencies.
msw -

Published by kettanaito over 3 years ago

Bug fixes

  • Fixes the operability issue when used in React Native (#622, #808, #809, #810).
msw -

Published by kettanaito over 3 years ago

Bug fixes

  • Fixes an issue when the original HTTPS requests were not correctly performed in Node.js (#700, #797).
msw -

Published by kettanaito over 3 years ago

Features

  • Supports generators as response resolvers (#720).
rest.get('/polling/:maxCount', function* (req, res, ctx) {
  const { count } = req.params
	let count = 0

	while (count < req.params. maxCount) {
	  yield res(ctx.json({ count }))
	}

	return res(ctx.json({ done: true }))
})
  • Adds the ctx.cookie utility to the GraphQL handlers (#763).
  • Adds a warning when running MSW on a page that’s outside of the worker’s scope (#787).
  • The worker script (mockServiceWorker.js) now contains the library version number to improve its inspection and debugging across releases (#781).

Bug fixes

  • Fixes various issues to ensure Jest 27 compatibility.
  • Fixes an issue that prevented the assignment of more narrow response types (#735).
  • Fixes an issue when parsing a GraphQL-compatible REST API request produced a parsing error during the onUnhandledRequest default behavior (#740).
msw -

Published by kettanaito over 3 years ago

Breaking changes

  • The onUnhandledRequest option is set to "warn" by default (previously ”bypass") (#703).

Features

  • Adds Fallback mode. This enables MSW in browsers that don’t support Service Worker API, or in the applications that run from a static file (#688). Fallback mode is enabled internally and is not configurable.
  • Running npx msw init now recursively creates a non-existing worker directory (#699).

Bug fixes

  • Fixes an issue that resulted in a memory leak when running multiple tests dependent on setupServer (https://github.com/mswjs/interceptors/pull/116).
  • Fixes an issue that resulted in a proper XML response body not being accessible under xhrInstance.responseXML in Node.js (#715).
  • Fixes an issue when an expired response cookie persisted on a mocked response after its expiration date (https://github.com/mswjs/msw/issues/708).
  • Fixes an issue that resulted in ESLint complaining about the pragma comment of the worker script (#693).

Internal

  • Updates dependencies to the latest versions (#747).
msw -

Published by kettanaito over 3 years ago

Bug fixes

  • Fixes an issue when req.params was undefined in case when request path had no parameters present (#682, #684). The req.params value is always an object, regardless if you have path parameters defined.
msw -

Published by kettanaito over 3 years ago

Bug fixes

  • Fixes the issue that resulted in the "Cannot read property 'id' of undefined" in iframe scenarios (#643, #645).
  • Fixes the issue when making an explicit return in a handler considered the request unhandled in Node.js (#655, #672).
  • Fixes the issue that resulted in a multipart form data not being parsed correctly given extra spaces or the lack of such in the Content-Type header (#671).
msw -

Published by kettanaito over 3 years ago

Breaking changes

  • The response instance in the life-cycle events now handles response.headers as the Headers instance (#660).
server.on('response:bypass', (res) => {
-  res.headers['content-type']
+  res.headers.get('content-type')
})
  • Calling setupServer no longer applies request interception immediately. Instead, it's applied when called server.listen() (#660).

Bug fixes

  • Fixes the order of events in the intercepted XMLHttpRequest in Node.js (https://github.com/mswjs/interceptors/pull/102).
  • Fixes an issue that resulted in the "TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"" exception when using MSW with superagent (#632).

Internal

  • Updates dependencies (@mswjs/interceptors, headers-utils).
msw -

Published by kettanaito over 3 years ago

Bug fixes

  • Fixes a backward-compatibility issue of the DropFirstInTuple type used internally in compose.ts (#658).
  • Fixes an issue in IE11 when retrieving a stack trace of a handler would throw an exception (#647).
  • Fixes an issue when a stream in a response body would cause a response timeout (#602).
  • Fixes an issue when a cookie retrieval would cause a Fast Refresh to break in Next.js (#649).
msw -

Published by kettanaito over 3 years ago

Changes

  • Exports the RestHandler class publicly.

Bug fixes

  • Fixes an issue that caused a Uncaught ReferenceError: process is not defined exception when calling worker.start() (#609, #629).
  • Fixes an issue that caused a TypeScript violation in the PickLastInTuple type (#615, #627).
  • Fixes an issue that caused an TypeError: Object.fromEntries is not a function error when running MSW in Node.js v10 (#625, #633).

Internals