Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update msw to v2 #416

Merged
merged 1 commit into from
Oct 23, 2023
Merged

chore(deps): update msw to v2 #416

merged 1 commit into from
Oct 23, 2023

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Oct 23, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
msw (source) 0.0.0-fetch.rc-20 -> 2.0.0 age adoption passing confidence

Release Notes

mswjs/msw (msw)

v2.0.0

Compare Source

v2.0.0 (2023-10-23)

[!IMPORTANT]
This release is a BREAKING CHANGE. Please follow the Migration guidelines to upgrade. This release took a lot of effort to make, and I expect a bit of that effort on your part while upgrading. Most of the changes are mechanical, and a simple Find/Replace All will get you a long way. For the rest of it, you will learn how to handle requests and responses using the standard JavaScript API. Thank you!

Breaking changes

  • Drops support for Node.js 16. Please upgrade to Node.js 18 or later to use the global Fetch API.
  • Drops support for TypeScript < 4.7.
  • All browser-side exports, like setupWorker, SetupWorkerApi, etc., must be imported from msw/browser now.
  • Renames the rest object to http (rest.get -> http.get).
  • Response resolver call signature is no longer (req, res, ctx) => res() but instead ({ request }) => new Response().
  • The following exports are removed due to no longer being needed:
    • response
    • context and related exports (defaultContext, restContext, graphqlContext).
    • compose and createResponseComposition
  • res.once() is removed in favor of the { once: boolean } option on the request handler.
  • Replaces the .printHandlers() method with .listHandlers().
  • Removes the NetworkError class in favor of the standard Response.error().
  • Moves request error handling from the worker thread to the client thread.
  • Changes the call signature of the Life-cycle Events API to accept a single object argument.
  • Uses crypto.randomUUID() instead of Math.random() in the worker.
  • For the full list of changes and detailed instructions on how to upgrade please see the Migration guidelines.

Features

  • Adopts Fetch API primitives. Represent intercepted requests and mocked responses as Request and Response instances respectively.
  • Supports Node.js v18.
  • Supports ReadableStream as a mocked response body.
  • Supports reading the intercepted request body as FormData.
  • Supports FormData as a mocked response body.
  • Uses File polyfill in Node.js.
  • Supports XMLHttpRequest “upload” events when responding with a mocked stream response.
  • Allows mocking a network error once using the { once: true } request handler option.
  • Makes the RequestHandler API public.

Bug fixes

  • Fixes the issue where the request body couldn’t be properly read as FormData.
  • Fixes a set of issues related to response patching when using the FormData response body.
  • Fixes the issue where URLSearchParams as the request body couldn’t be read.
  • Fixes the issue where a bypassed request’s referrerPolicy was reset to a different value than the original.
  • Fixes the wrong order of XMLHttpRequest events and readyState changes.
  • Fixes the issue when reading an XMLHttpRequest body of responseType equal to "arraybuffer" as an incorrect buffer (previously, always assumed to be a string).
  • Fixes the order of XMLHttpRequest events when the request fails.
  • Keeps XMLHttpRequest status equal to 0 until the request actually resolves.
  • Fixes the issue when the onload event callback was called twice for XMLHttpRequest.
  • Various improvements in Node.js network behavior compliance.

@​dbritto-dev @​ddolcimascolo @​markwhitfeld @​christoph-fricke @​thepassle @​piotr-cz @​mattcosta7 @​koddsson @​dkobierski @​ricardocosta @​dxlbnl @​zkochan @​felipefreitag @​weyert @​95th @​committomaster @​Xayer @​Kosai106 @​colinsullivan @​xmlking @​thw0rted @​lee-reinhardt @​wKovacs64 @​TeChn4K @​cmolina @​nickrttn @​thomasbertet @​mscottnelson @​jonnedeprez @​negabaro @​the-ult @​WesleyYue @​cwagner22 @​skvale @​alawiii521 @​csantos1113 @​elliotgonzalez123 @​committomaster @​tsteckenborn @​xxleyi @​jonnedeprez @​danny-does-stuff @​lemcii @​mattrodak @​luisr-carrillo @​lee-reinhardt @​ealejandrootalvaro @​tomdglenn91

v1.3.2

Compare Source

v1.3.2 (2023-10-01)

Bug Fixes

v1.3.1

Compare Source

v1.3.1 (2023-09-13)

Bug Fixes

v1.3.0

Compare Source

v1.3.0 (2023-09-03)

Features

v1.2.5

Compare Source

v1.2.5 (2023-08-28)

Bug Fixes

v1.2.4

Compare Source

v1.2.4 (2023-08-25)

Bug Fixes

v1.2.3

Compare Source

v1.2.3 (2023-07-20)

Bug Fixes

v1.2.2

Compare Source

v1.2.2 (2023-06-09)

Bug Fixes

v1.2.1

Compare Source

v1.2.1 (2023-03-24)

Bug Fixes

v1.2.0

Compare Source

v1.2.0 (2023-03-22)

Features

v1.1.1

Compare Source

v1.1.1 (2023-03-20)

Bug Fixes

v1.1.0

Compare Source

v1.1.0 (2023-02-24)
Features
Bug Fixes

v1.0.1

Compare Source

v1.0.1 (2023-02-10)

Bug Fixes

v1.0.0

Compare Source

v1.0.0 (2023-01-25)

⚠️ BREAKING CHANGES
Features

v0.49.3

Compare Source

v0.49.3 (2023-01-19)

Bug Fixes

v0.49.2

Compare Source

v0.49.2 (2022-12-13)
Bug Fixes

v0.49.1

Compare Source

v0.49.1 (2022-11-28)

Bug Fixes

v0.49.0

Compare Source

v0.49.0 (2022-11-19)

Features

v0.48.3

Compare Source

v0.48.3 (2022-11-15)

Bug Fixes

v0.48.2

Compare Source

v0.48.2 (2022-11-13)

Bug Fixes

v0.48.1

Compare Source

v0.48.1 (2022-11-10)

Bug Fixes

v0.48.0

Compare Source

v0.48.0 (2022-11-08)

Features

v0.47.4

Compare Source

v0.47.4 (2022-10-04)

Bug Fixes

v0.47.3

Compare Source

v0.47.3 (2022-09-15)

Bug Fixes

v0.47.2

Compare Source

v0.47.2 (2022-09-13)

Bug Fixes

v0.47.1

Compare Source

v0.47.1 (2022-09-10)

Bug Fixes

v0.47.0

Compare Source

v0.47.0 (2022-09-04)

Features

v0.46.1

Compare Source

v0.46.1 (2022-09-01)

Bug Fixes

v0.46.0

Compare Source

v0.46.0 (2022-08-31)

Features
server.listHandlers()
worker.listHandlers()

v0.45.0

Compare Source

v0.45.0 (2022-08-22)

Features
  • make GraphQL a peer dependency, support GraphQL v15.0 (#​1356) (ca0e2e0)

v0.44.2

Compare Source

v0.44.2 (2022-07-19)

Bug Fixes
  • transfer mocked response as ArrayBuffer to the worker (#​1337) (95be5f8)

v0.44.1

Compare Source

v0.44.1 (2022-07-14)

Bug Fixes

v0.44.0

Compare Source

v0.44.0 (2022-07-13)

Breaking changes
  • req.destination default value is now "" (empty string), previously "document".
  • req.redirect default value is now ""follow", previously "manual".
  • The library no longer exports the parseIsomorphicRequest() function (#​1316). Please use MockedRequest class instead.
Features
Deprecations
  • req.body is deprecated. Please use explicit request body reading methods: req.text(), req.json(), req.arrayBuffer() (other methods, like req.formData() are currently not supported).
rest.post('/user', async (req, res, ctx) => {
  const newUser = await req.json()
})

req.body is still present for compatibility reasons but will be removed in the next releases.

v0.43.1

Compare Source

v0.43.1 (2022-07-07)

Bug Fixes
  • support multiple response cookies using "ctx.cookie()" (#​1311) (66c3ad8)

v0.43.0

Compare Source

v0.43.0 (2022-07-04)

Features
  • send mocked response body as ReadableStream to the worker (#​1288) (78c7d7e)

v0.42.3

Compare Source

v0.42.3 (2022-06-22)

Bug Fixes

v0.42.2

Compare Source

v0.42.2 (2022-06-22)

Bug Fixes
  • setupServer: reference interceptors to support fast refresh (#​1299) (72f0b25)

v0.42.1

Compare Source

v0.42.1 (2022-06-07)

Bug Fixes

v0.42.0

Compare Source

v0.42.0 (2022-05-30)

Features
Bug Fixes

v0.41.1

Compare Source

v0.41.1 (2022-05-27)

Bug Fixes

v0.41.0

Compare Source

v0.41.0 (2022-05-22)

Features

v0.40.2

Compare Source

v0.40.2 (2022-05-20)

Bug Fixes

v0.40.1

Compare Source

v0.40.1 (2022-05-19)

Bug Fixes

v0.40.0

Compare Source

v0.40.0 (2022-05-17)

Breaking changes
  • Returning undefined, or early returns, from response resolvers, now does not perform request as-is, and is instead treated as a handler that didn't do anything. Please return req.passthrough() if you wish to bypass a request.
rest.get('/resource', (req, res, ctx) => {
// I want to perform this intercepted request as-is.
-  return
+  return req.passthrough()
})
Features
Bug Fixes
  • setupWorker: warn on multiple "worker.start" and "worker.stop" calls (#​1238) (cfe0709)
  • remove console.log from "setRequestCookies" (6f7ed98)
  • set "credentials" to "same-origin" for "ClientRequest" (#​1159) (c3cd80a)

v0.39.2

Compare Source

Bug Fixes

v0.39.1

Compare Source

Bug Fixes

v0.39.0

Compare Source

Breaking changes
Bug Fixes
  • setupWorker: resolve the "start" promise after the worker has activated (#​1146) (f6e709c)

v0.38.2

Compare Source

Bug Fixes

v0.38.1

Compare Source

Bug Fixes
  • handleRequest: bypass request only if "x-msw-bypass" header equals "true" (#​1110) (1a7bc36)

v0.38.0

Compare Source

Features
worker.start({
  onUnhandledRequest(request, print) {
    // Ignore unhandled warnings/errors from asset requests.
    if (request.url.href.includes('/assets/') {
      return
    }

    // Otherwise, execute the default warning/error/ strategy.
   print.warning() // or "print.error()" 
  }
})

v0.36.8

Compare Source

Bug Fixes

v0.36.7

Compare Source

Bug Fixes

v0.36.5

Compare Source

Bug Fixes
  • parse request body with letter case Content-Type header value (#​1064) (7796418)

v0.36.4

Compare Source

Bug fixes

  • Fixes an issue that resulted in port numbers being treated as path parameters (#​1036, #​1028).

v0.36.3

Compare Source

Bug fixes

  • Fixes an issue that resulted in the CORS policy violation due to the library appending the x-msw-request-id request header (#​713, #​1022, #​1024).

Internal

  • No longer sets the x-msw-request-id header on the request (#​1024). Relies on the request.id set by the interceptors (Node.js) or the requestId generated by the worker (browser).

v0.36.2

Compare Source

Bug fixes

  • Fixes an issue that resulted in the "TypeError: expected.toLowerCase() is not a function" exception when using the rest.all() request handler (#​1020, #​1021).

v0.36.1

Compare Source

Bug fixes

  • Fixes an issue that resulted in the "SyntaxError: Invalid group specified name" exception in Safari (#​1018, #​1019 ).

v0.36.0

Compare Source

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.

v0.35.0

Compare Source

v0.34.0

Compare Source

v0.33.3

Compare Source

v0.33.2

Compare Source

v0.33.1

Compare Source

v0.33.0

Compare Source

v0.32.3

Compare Source

v0.32.2

Compare Source

v0.32.1

Compare Source

v0.32.0

Compare Source

v0.31.0

Compare Source

v0.30.1

Compare Source

v0.30.0

Compare Source

v0.29.0

Compare Source

v0.28.2

Compare Source

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.

v0.28.1

Compare Source

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).

v0.28.0

Compare Source

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

v0.27.2

Compare Source

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).

v0.27.1

Compare Source

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

v0.27.0

Compare Source

Breaking changes

  • The Promise returned by worker.start() will now reject in the case of any errors during the worker registration (#​607).
  • The library no longer exports the following TypeScript declarations:
    • RestRequestType, use RestRequest instead.
    • GraphQLMockedRequest, use GraphQLRequest instead.
    • GraphQLMockedContext, use GraphQLContext instead.
    • GraphQLRequestPayload, use GraphQLRequestBody instead.
    • GraphQLRequestParsedResult, use ParsedGraphQLRequest instead.
    • GraphQLResponseResolver
  • The values of the MockedRequest type no longer have the params key (#​561). Please use the RestRequest type to annotate REST API requests instead.

Features

  • Supports automatic worker script updates (#​606). Respects the msw.workerDirectory property in your package.json:
{
  "msw": {
    "workerDirectory": "public"
  }
}

Starting from this release, whenever you install msw, it will try to locate the msw.workerDirectory property in your package.json and copy the relevant worker script (mockServiceWorker.js) to that directory.

Whenever running msw init now, you will be prompted to save your public directory choice to package.json.

  • When running msw init you can pass the —save option to automatically save the public directory in your package.json for future worker updates (#​606). You can alternatively use --no-save to bail out this step.
  • Intercepts requests originating from an iframe (#​589).
  • Adds virtual cookie store to ensure the persistency of cookies received from the same domains across multiple requests (#​435, #​469).

Bug fixes

  • Fixes an issue when a request body type generic had no effect on the response composition chain validation.
  • Fixes an issue when a 204 response threw an exception when the library emitted its response:* life-cycle events (#​570).

Internal

  • Rebuilds the Request Handler API from ground-up (#​561). Does not introduce any breaking changes in how you use the handlers.
  • Fixes the auto-imports of the library’s methods suggested by IDE (#​598).
  • Updates the dependencies.

v0.26.2

Compare Source

Bug fixes
  • Fixes an issue that resulted in GraphQL request handlers not annotating the mocked response structure based on the given generic type (#​587).
  • Fixes an issue when a one-time request handler (res.once) affected multiple matching requests made in parallel (#​583).
  • Properly exports the renamed OnUnhandledRequest type as the new UnhandledRequestStrategy type (#​577).

v0.26.1

Compare Source

Features
  • onUnhandledRequest option will now suggest similar request handlers based on the URL/operation name similarity (#​560).
Bug fixes
  • Fixes an issue that resulted in a 202 status response throwing an exception when the library attempted to re-create its Response instance for the response:* life-cycle event (#​570).
  • Fixes an issue when a request handler stack trace wasn't handled properly on Windows machines (#​566).
  • Fixes an issue when using the onUnhandledRequest: "error" option resulted in a thrown exception being gracefully handled by Axios (#​544). The "error" value now prints to stderr directly instead of throwing an exception. An original request-related exception will become visible now as well.

v0.26.0

Compare Source

This release introduces changes to the mockServiceWorker.js file. Please follow the instructions in the browser to update the worker file. Thank you.

Features
  • Adds support for GraphQL upload and multipart data operations (#​215, #​543).
  • Adds delay modes: “real” and “infinite” (#​538). Supports infinite loading.
ctx.delay() // random realistic response time
ctx.delay('real') // the same as `ctx.delay()`
ctx.delay('infinite') // infinite response time
ctx.delay(50) // explicit response delay (50ms)
  • Displays [MSW] Mocking disabled message when calling worker.stop(). (#​485, #​493).
Bug fixes
  • Fixes an issue that resulted in theFailed to construct 'Response': The status provided (0) is outside the range [200, 599]. exception caused by an opaque response on the page (#​529, #​564). MSW will now skip opaque responses during the life-cycle events handling. You will not get the response:bypass invoked upon an opaque response.
  • Fixes an issue that resulted in an exception being thrown when handling subsequent requests in Safari (#​558, #​565).
  • Fixes an issue when the ExecutionResult of graphql was not compatible with ctx.data and ctx.errors utilities (#​522, #​542).
  • Fixes an issue that resulted in the MSW worker handling unrelated message event originating from other tools (#​551).
Internal
  • Updates dependencies to their latest versions.
  • Consistently uses self instead of this in the worker script (#​568).
  • Ensures that MSW doesn’t handle events originating from unrelated workers (#​551).

v0.25.0

Compare Source

Features

v0.24.4

Compare Source

Features

  • Exports the RestContext type interface for public consumption (#​524).

v0.24.3

Compare Source

Features
  • Publishes the library in IIFE format, allowing to use it from a <script> tag (#​507, #​509).
Internal
  • Updates package's dependencies (#​521).

v0.24.2

Compare Source

v0.24.1

Compare Source

Improvements
  • Ships with refined JSDoc support (#​483). Most of the core functions and methods now include concise description, usage example, and a link to the docs.

v0.24.0

Compare Source

Breaking changes
  • ctx.json context utility now always stringifies the response body (#​468).
  • Removes JSON response body transformer as the default response body transformer. Nothing implicitly transforms the response body now.
Migration guidelines
  • Replace custom response transformers that might have affected the end response body, such as custom serializers, with custom response transformers.
Bug fixes
  • Fixes an issue that resu

Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@changeset-bot
Copy link

changeset-bot bot commented Oct 23, 2023

⚠️ No Changeset found

Latest commit: 35c266d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@wKovacs64 wKovacs64 merged commit 799545d into main Oct 23, 2023
9 checks passed
@wKovacs64 wKovacs64 deleted the renovate/msw-2.x branch October 23, 2023 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant