Developer tool case study
Building MSW Inspector: finding stale and missing mocks with AST analysis.
MSW Inspector is an open-source TypeScript developer tool for checking whether a codebase's Mock Service Worker handlers still match the API calls the application actually makes. It ships as an npm CLI and a GitHub Marketplace Action.
01 / Problem
Mock coverage drifts away from product code.
MSW works best when handlers represent the real request surface of the application. Over time, that relationship drifts: new API calls arrive without matching handlers, and old handlers remain after product code stops calling those endpoints.
Both problems weaken test confidence. Missing handlers hide integration gaps. Stale handlers create a mock layer that looks comprehensive but no longer reflects current product behavior.
02 / What I built
One analysis path from source code to CI evidence.
- TypeScript CLI that scans source files for API calls.
- MSW handler scanner for modern http.* and legacy rest.* handlers.
- Static endpoint extraction for fetch, Axios, and axios.create.
- Normalization layer for methods, origins, and paths.
- CI-friendly JSON output and threshold flags.
- GitHub Action wrapper for job summaries and pull-request workflows.
03 / Technical approach
AST analysis instead of text matching.
The CLI uses ts-morph so the scanner can inspect TypeScript and JavaScript syntax, identify call expressions, and evaluate static URL expressions where the source code makes them available.
It collects API call sites and MSW handler registrations, normalizes both sides into comparable endpoint records, then reports unmocked calls, stale handlers, and unsupported dynamic patterns. Unsupported output is deliberate: CI tooling should report what it can prove instead of fabricating coverage.
04 / Proof runs
The report makes gaps concrete.
| Repository | Handlers | API calls | Unmocked | Stale | Unsupported | What it shows |
|---|---|---|---|---|---|---|
| TypeJung | 0 | 39 | 39 | 0 | 11 | A real app can have auth, billing, analytics, and AI endpoints with no mock coverage. |
| Mirror | 0 | 7 | 7 | 0 | 3 | A smaller product still exposes clear gaps around journal, AI, and Stripe routes. |
| MSW browser REST slice | 66 | 0 | 0 | 66 | 0 | A narrowed scan can also reveal handlers outside the scanned active call surface. |
05 / Outcome
A maintained tool, not a one-off parser.
The project demonstrates end-to-end developer tooling work: AST parsing, CLI design, report formats, CI integration, npm packaging, GitHub Marketplace distribution, and clear handling of static-analysis limits.
The next product work is config-file support, more framework examples, clearer unsupported-pattern messages, and baseline or delta reporting for pull requests.