Skip to content

Releases: mswjs/msw

v0.18.1

04 Jun 08:06
Compare
Choose a tag to compare

Bug fixes

  • Fixes an outdated repository URL in the Service Worker activation message.
  • Fixes an issue that resulted into ReferenceError: location is not defined error when using a request handler with a relative URL in setupServer (#193)

v0.18.0

30 May 11:36
Compare
Choose a tag to compare

Features

rest.get('/books', (req, res, ctx) => {
  return res.once(ctx.json([1, 2, 3]))
})

Bug fixes

  • Fixes an issue that resulted into the following TypeScript error when installing msw (#185, #186 ):
TS7016: Could not find a declaration file for module 'cookie'
  • Fixes an outdated GitHub repository link in the mockServiceWorker.js file.

v0.17.2

25 May 15:50
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that caused an empty non-JSON request body being parsed as JSON (#175, #179)

v0.17.1

24 May 08:31
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that resulted into responses to axios requests not being mocked properly (#180, #181).

Internal

  • Lists node-request-interceptor as an external dependency of the msw/node bundle.

v0.17.0

21 May 08:39
Compare
Choose a tag to compare

Features

  • Custom request handlers have reworked lifecycle and accept new methods:
    • parse(), to retrieve additional information about the request before the predicate.
    • getPublicRequest(), to modify the original request with public information (i.e. adding req.params or req.variables).

Bug Fixes

  • Fixes an issue that resulted into GraphQL mutations not being logged properly (#161, #176)

v0.16.2

20 May 10:10
Compare
Choose a tag to compare

Features

  • GraphQL requests are now being printed into browser’s console using a proper format (operation name / response status) (#161, #174)
  • Each custom request handler can have its own log function that controls what and how gets printed into browser’s console for introspection:
// my-handler.js
export const myHandler = () => {
  return {
    log(req, res, handler) {
      console.log('%s %s', req.method, req.url.href)
    }
  }
}

The information available in the log function:

  • req, intercepted request instance;
  • res, resolved mocked response object;
  • handler, exact request handler that captured this request.

Bug fixes

  • Fixes an issue that resulted into a request body with the Content-Type: application/json to be unparsed in req.body reference of the request handler (#171, #172).

v0.16.1

19 May 21:04
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that resulted into a relative request's URL being printed as absolute in the browser's console (#164, #167).
  • Fixes an issue that resulted into a request JSON body not being parsed inside a request handler (#159, #168).

v0.16.0

16 May 10:24
Compare
Choose a tag to compare

This release introduces bug fixes to the Service Worker file. Please follow the update instructions in your browser's console. Thanks.

Breaking changes

  • The req.url reference in request handlers is now a URL instance (#158):
rest.get('/user', (req) => {
-  req.url // "/user"
+  req.url.href // "/user"
})

Features

  • Adds support for running in NodeJS (#104, #146, docs). This makes it possible to use the same mock definition for unit and integration tests.
// test/LoginForm.test.js
import { rest } from 'msw'
import { setupServer } from 'msw/node'

describe('LoginForm', () => {
  const server = setupServer(
    rest.post('/login', (req, res, ctx) => {
      return res(ctx.json({ success: true }))
    })
  )

  beforeAll(() => {
    server.listen()
  })

  afterAll(() => {
    server.close()
  })

  it('allows a user to log in', () => {
    // your assertions here...
  })
})

Bug fixes

  • Fixes an issue that resulted into the last value of a multi-value header being available in req.headers (#154)

v0.15.9

12 May 20:07
Compare
Choose a tag to compare

This release contains changes to mockServiceWorker.js file. Please follow the instructions in your browser's console to update the worker file.

Bug fixes

  • Fixes an issue that resulted into failed mocking with multiple pages open after page refresh (#139, #155).
  • Fixes an issue that resulted into the following exception when using ctx.fetch() (#150, #151):
Failed to execute 'text' on 'Response': body stream is locked
  • Fixes an issue that resulted into nested paths attempting to register the mockServiceWorker.js file relatively to the path, instead of the root (#152, #153).

v0.15.8

11 May 06:03
Compare
Choose a tag to compare

Bug fixes

  • Fixed an issue that resulted into request headers not being propagated to an actual request when calling ctx.fetch() to perform response patching (#145, #149).
  • Fixed an issue that resulted into an exception when trying to register a Service Worker in a non-supported environment (legacy browser, or custom hostname) (#147, #148).