Vitest Memfs
Started
Project Overview
vitest-memfs adds a set of memfs-aware matchers to Vitest, enabling file-heavy integration tests to run in memory while using Vitest’s regular expect API.
Why
I often build tooling (bundlers, project scaffolds, CLIs) that pipes files through memfs to avoid touching the real disk.
Assertions turned into hand-written vol.existsSync checks and fragile object diffs.
The package extracts the helpers I rewrote across projects into a reusable set of matchers with tight TypeScript support, glob awareness, and snapshot integration.
Key Matchers
toHaveVolumeEntries— assert that exact paths or glob patterns exist in a volume, optionally verifying the entry type (file,dir,symlink) or an expected count.toMatchVolume— compare an in-memory volume against another volume or JSON tree with support forprefix,ignore, and directory list matching modes (exact, ignore-extra, ignore-missing).toMatchVolumeSnapshot— persist a snapshot of a volume to disk (under__snapshots__/) and diff future runs; supports async comparison, glob ignores, and throttled concurrency for large trees.
All matchers share a consistent options object (prefix, ignore, listMatch, contentMatch, report, async, concurrency) so tests can zoom in on the interesting slice of the filesystem without noise.
Tooling Notes
- Written in TypeScript, bundled with
pkgroll, and built for Node 18+ in both ESM and CJS formats. - CI runs Vitest on both Linux and Windows to ensure cross-platform compatibility, collects coverage with V8 + Codecov, and handles automated releases through Semantic Release.
- Exposes a setup entry (
vitest-memfs/setup) plus matcher and utility subpaths exports.
Check out the project repository on Github for more info.