npm msw 0.36.0

latest releases: 2.6.2, 2.6.1, 2.6.0...
2 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 (mswjs/interceptors#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.

Don't miss a new msw release

NewReleases is sending notifications on new releases.