Skip to content

Replace axios-mock-adapter with MSW (Mock Service Worker) #12514

Description

@offtherailz

Description

axios-mock-adapter (v2.1.0) has shown brittleness with the axios 0.32.0 upgrade: it accesses config.headers.constructor.name directly, crashing when axios returns null-prototype objects (a security hardening introduced in 0.32.0 to prevent prototype pollution).

A workaround was applied in #12447 (postInstall.js patch + {...config.params} spreads in tests), but this reveals a structural issue: axios-mock-adapter hooks into axios adapter internals and is fragile against upstream changes.

The proposal is to replace it with MSW (Mock Service Worker) (or something alternative) which intercepts requests at the network level (Service Worker in browser, http/https in Node) and is completely agnostic of the HTTP client used (axios, fetch, ky, etc.).

What kind of improvement you want to add? (check one with "x", remove the others)

  • Minor changes to existing features
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

Other useful information

  • MSW supports karma/browser test environments via msw/browser + Service Worker
  • Migration can be done incrementally per test file
  • Once complete, remove patchAxiosMockAdapter from utility/build/postInstall.js
  • Related: Bump axios from 0.30.3 to 0.32.0 #12447

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions