René's URL Explorer Experiment


Title: test_runner: add experimental `mock.fs` API by sozua · Pull Request #61468 · nodejs/node · GitHub

Open Graph Title: test_runner: add experimental `mock.fs` API by sozua · Pull Request #61468 · nodejs/node

X Title: test_runner: add experimental `mock.fs` API by sozua · Pull Request #61468 · nodejs/node

Description: Add experimental mock.fs API to the test runner for mocking file system operations in tests. This allows tests to simulate file operations without actually reading from or writing to disk. Note: There is an existing draft PR #59194 by @joaoGabriel55 working on this feature, though it appears to have stalled (last updated August 2025). This implementation takes a different approach based on maintainer feedback in the issue discussion: Uses mock.fs naming as suggested by @MoLow Gated behind --experimental-test-fs-mocks flag as suggested by @ljharb Includes callback and promise variants, not just sync methods Features Virtual file system with string, Buffer, or Uint8Array content Supports sync, callback, and promise variants of fs APIs Mocked APIs: readFile, writeFile, appendFile, stat, lstat, access, exists, unlink, mkdir, rmdir, readdir Isolation mode (isolate: true) to completely block real filesystem access Selective API mocking via the apis option Write operations always go to virtual fs (prevents accidental disk writes) Symbol.dispose support for automatic cleanup Examples Basic usage import { test } from 'node:test'; import fs from 'node:fs'; import assert from 'node:assert'; test('mock file system', (t) => { t.mock.fs.enable({ files: { '/virtual/config.json': '{"key": "value"}', }, }); const config = JSON.parse(fs.readFileSync('/virtual/config.json', 'utf8')); assert.strictEqual(config.key, 'value'); }); Isolation mode test('complete isolation from real filesystem', (t) => { t.mock.fs.enable({ files: { '/virtual/only.txt': 'isolated content', }, isolate: true, }); // Virtual file works assert.strictEqual(fs.readFileSync('/virtual/only.txt', 'utf8'), 'isolated content'); // Real files are blocked assert.throws(() => fs.readFileSync('/etc/passwd'), { code: 'ENOENT' }); }); Write operations test('writes always go to virtual fs', (t) => { t.mock.fs.enable({ files: {} }); // Write to virtual fs fs.writeFileSync('/tmp/test.txt', 'safe write'); // Read it back assert.strictEqual(fs.readFileSync('/tmp/test.txt', 'utf8'), 'safe write'); // After test ends, nothing written to real /tmp }); Async/promises import fsPromises from 'node:fs/promises'; test('works with promises', async (t) => { t.mock.fs.enable({ files: { '/data/file.txt': 'async content' }, }); const content = await fsPromises.readFile('/data/file.txt', 'utf8'); assert.strictEqual(content, 'async content'); }); Directory operations test('directory operations', (t) => { t.mock.fs.enable({ files: { '/app/src/index.js': 'console.log("hello")', '/app/src/utils.js': 'export default {}', }, }); const entries = fs.readdirSync('/app/src'); assert.deepStrictEqual(entries.sort(), ['index.js', 'utils.js']); }); Next Steps This PR provides an initial set of commonly-used fs operations. Future iterations could add file operations like rename, copyFile, rm, and truncate, as well as symlink support (symlink, readlink, link). Refs: #55902

Open Graph Description: Add experimental mock.fs API to the test runner for mocking file system operations in tests. This allows tests to simulate file operations without actually reading from or writing to disk. Note: Th...

X Description: Add experimental mock.fs API to the test runner for mocking file system operations in tests. This allows tests to simulate file operations without actually reading from or writing to disk. Note: Th...

Opengraph URL: https://github.com/nodejs/node/pull/61468

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:388fa877-d608-f258-cbff-4ee9be471b66
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA2C0:951F5:17FE288:22D3B19:6A4CECA5
html-safe-nonce490fda920eee53175f1bc510c6bb9c68d02ac46dd83a49c9d26bccc7f60a59d2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkMwOjk1MUY1OjE3RkUyODg6MjJEM0IxOTo2QTRDRUNBNSIsInZpc2l0b3JfaWQiOiI0MDEyOTcxMDMyMzAyMTIwMTAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1f31b8facaa35946db542eece9d65213edc6a166b46e29eb590c61ee7fb11a85
hovercard-subject-tagpull_request:3197963229
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/nodejs/node/pull/61468/files
twitter:imagehttps://avatars.githubusercontent.com/u/41171734?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/41171734?s=400&v=4
og:image:altAdd experimental mock.fs API to the test runner for mocking file system operations in tests. This allows tests to simulate file operations without actually reading from or writing to disk. Note: Th...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None299b43bca6e02ad35197ffeba30d2466846d5fb02ab96fbced5b5e6cec589fb8
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseefec6750a5afcaeaf5dfcf629f404cf98c8371e3
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodejs/node/pull/61468/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fpull%2F61468%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fpull%2F61468%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/pull/61468/files
Reloadhttps://github.com/nodejs/node/pull/61468/files
Reloadhttps://github.com/nodejs/node/pull/61468/files
Please reload this pagehttps://github.com/nodejs/node/pull/61468/files
nodejs https://github.com/nodejs
nodehttps://github.com/nodejs/node
Please reload this pagehttps://github.com/nodejs/node/pull/61468/files
Notifications https://github.com/login?return_to=%2Fnodejs%2Fnode
Fork 36k https://github.com/login?return_to=%2Fnodejs%2Fnode
Star 118k https://github.com/login?return_to=%2Fnodejs%2Fnode
Code https://github.com/nodejs/node
Issues 1.4k https://github.com/nodejs/node/issues
Pull requests 959 https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality 0 https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Code https://github.com/nodejs/node
Issues https://github.com/nodejs/node/issues
Pull requests https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fnodejs%2Fnode%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fnodejs%2Fnode%2Fissues%2Fnew%2Fchoose
sozuahttps://github.com/sozua
nodejs:mainhttps://github.com/nodejs/node/tree/main
sozua:test_runner/mock-file-systemhttps://github.com/sozua/node/tree/test_runner/mock-file-system
Conversation 51 https://github.com/nodejs/node/pull/61468
Commits 8 https://github.com/nodejs/node/pull/61468/commits
Checks 0 https://github.com/nodejs/node/pull/61468/checks
Files changed https://github.com/nodejs/node/pull/61468/files
Please reload this pagehttps://github.com/nodejs/node/pull/61468/files
test_runner: add experimental mock.fs API https://github.com/nodejs/node/pull/61468/files#top
Show all changes 8 commits https://github.com/nodejs/node/pull/61468/files
581475d test_runner: add mock file system support sozua Jan 22, 2026 https://github.com/nodejs/node/pull/61468/commits/581475d83e1835508900ead9c43994ff26e2d4cd
c12a9b7 doc: document mock file system for test runner sozua Jan 22, 2026 https://github.com/nodejs/node/pull/61468/commits/c12a9b7115f8feb5acb05d4aabfa27c59ff6f274
9d3ed17 doc: add --experimental-test-fs-mocks to manpage and fix option order sozua Jan 22, 2026 https://github.com/nodejs/node/pull/61468/commits/9d3ed17073c2ba76c993689e2599884ad1dd4201
5e8e835 test_runner: address review feedback for mock file system sozua Jan 22, 2026 https://github.com/nodejs/node/pull/61468/commits/5e8e835b68d518ecba506e3d086954bfc77f838a
93226ab test_runner: use call-bind pattern for BufferPrototypeToString sozua Jan 22, 2026 https://github.com/nodejs/node/pull/61468/commits/93226ab48adbe5b8dd23c398e7af12300a0e9ff9
502e48b test_runner: use uncurryThis for BufferPrototypeToString sozua Jan 22, 2026 https://github.com/nodejs/node/pull/61468/commits/502e48b7d093da0f48418e5f81c63ad1e9245438
f921730 test_runner: use path.join and ObjectDefineProperty in mock fs sozua Jan 23, 2026 https://github.com/nodejs/node/pull/61468/commits/f9217304bf3901e427be286342ea826c200fd76c
8fd61d7 test_runner: refactor mock fs stats and error handling sozua Jan 23, 2026 https://github.com/nodejs/node/pull/61468/commits/8fd61d7badb59d5ff2ec2db15c9927894c7ec47f
Clear filters https://github.com/nodejs/node/pull/61468/files
Please reload this pagehttps://github.com/nodejs/node/pull/61468/files
Please reload this pagehttps://github.com/nodejs/node/pull/61468/files
cli.md https://github.com/nodejs/node/pull/61468/files#diff-7349c17bce4d97526eefcb6f8291d617e7edb92ed9927fd3b9264e8014fc4e7c
test.md https://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
node.1 https://github.com/nodejs/node/pull/61468/files#diff-6319d8667880c119404aad5631a45e33a1ee70a4201282049872ac9d5d6f9295
mock.js https://github.com/nodejs/node/pull/61468/files#diff-87fe4fbfd23996c49072c2fb88829aaa0ed1be188b9da9d072471b0a523cd1c8
mock_file_system.js https://github.com/nodejs/node/pull/61468/files#diff-6bdfbfbbf74425720a4c955015e049b12f30655ecde256551b3bfae6a77c7169
node_options.cc https://github.com/nodejs/node/pull/61468/files#diff-d0b7433f8ca620eba56fc39f79429c73e2b3f061ca6d27583132a37b788b8aa8
node_options.h https://github.com/nodejs/node/pull/61468/files#diff-a6dd6c44925932d3134081da80ed07216f5f66449f540442835557616bcd14f9
test-runner-mock-file-system-dirs.js https://github.com/nodejs/node/pull/61468/files#diff-f144deae8f387662b61a35c0f75a70ad42875b41bad456954e6be1cf4b9c2ff8
test-runner-mock-file-system-no-flag.js https://github.com/nodejs/node/pull/61468/files#diff-fb238ca4060b5a4e579f1c91c2476b3603746784dbbcd5d8a3932be2c15f3367
test-runner-mock-file-system.js https://github.com/nodejs/node/pull/61468/files#diff-768cc12280f97df87fd32bed49a70a25fd86da5b15a8d36885525d77c138525e
doc/api/cli.mdhttps://github.com/nodejs/node/pull/61468/files#diff-7349c17bce4d97526eefcb6f8291d617e7edb92ed9927fd3b9264e8014fc4e7c
View file https://github.com/sozua/node/blob/8fd61d7badb59d5ff2ec2db15c9927894c7ec47f/doc/api/cli.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/61468/{{ revealButtonHref }}
https://github.com/nodejs/node/pull/61468/files#diff-7349c17bce4d97526eefcb6f8291d617e7edb92ed9927fd3b9264e8014fc4e7c
https://github.com/nodejs/node/pull/61468/files#diff-7349c17bce4d97526eefcb6f8291d617e7edb92ed9927fd3b9264e8014fc4e7c
https://github.com/nodejs/node/pull/61468/files#diff-7349c17bce4d97526eefcb6f8291d617e7edb92ed9927fd3b9264e8014fc4e7c
https://github.com/nodejs/node/pull/61468/files#diff-7349c17bce4d97526eefcb6f8291d617e7edb92ed9927fd3b9264e8014fc4e7c
doc/api/test.mdhttps://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
View file https://github.com/sozua/node/blob/8fd61d7badb59d5ff2ec2db15c9927894c7ec47f/doc/api/test.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/61468/{{ revealButtonHref }}
https://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
https://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
https://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
avivkellerhttps://github.com/avivkeller
Jan 22, 2026https://github.com/nodejs/node/pull/61468/files#r2716537457
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/nodejs/node/pull/61468/files
https://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
https://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
https://github.com/nodejs/node/pull/61468/files#diff-7ef19622f4f1c831ca0e6ed0edc03cb517f16969f1f1b0972a117bd3fa65c44a
doc/node.1https://github.com/nodejs/node/pull/61468/files#diff-6319d8667880c119404aad5631a45e33a1ee70a4201282049872ac9d5d6f9295
View file https://github.com/sozua/node/blob/8fd61d7badb59d5ff2ec2db15c9927894c7ec47f/doc/node.1
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/61468/{{ revealButtonHref }}
https://github.com/nodejs/node/pull/61468/files#diff-6319d8667880c119404aad5631a45e33a1ee70a4201282049872ac9d5d6f9295
https://github.com/nodejs/node/pull/61468/files#diff-6319d8667880c119404aad5631a45e33a1ee70a4201282049872ac9d5d6f9295
Please reload this pagehttps://github.com/nodejs/node/pull/61468/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.